Skip to content

Commit e50050b

Browse files
committed
[CSDiagnostics] Don't crash if we don't have access to the generic param's decl
1 parent fd387c5 commit e50050b

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3280,6 +3280,9 @@ bool MissingGenericArgumentsFailure::diagnoseForAnchor(
32803280
if (!diagnosed)
32813281
return false;
32823282

3283+
if (!hasDecl())
3284+
return true;
3285+
32833286
auto *DC = getDeclContext();
32843287
if (auto *SD = dyn_cast<SubscriptDecl>(DC)) {
32853288
emitDiagnostic(SD, diag::note_call_to_subscript, SD->getFullName());
@@ -3330,6 +3333,9 @@ bool MissingGenericArgumentsFailure::diagnoseParameter(
33303333
emitDiagnostic(loc, diag::unbound_generic_parameter, GP);
33313334
}
33323335

3336+
if (!hasDecl())
3337+
return true;
3338+
33333339
if (!hasLoc(GP))
33343340
return true;
33353341

lib/Sema/CSDiagnostics.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,8 @@ class MissingGenericArgumentsFailure final : public FailureDiagnostic {
14381438
return GP->getDecl()->getDeclContext();
14391439
}
14401440

1441+
bool hasDecl() const { return Parameters.front()->getDecl() != nullptr; }
1442+
14411443
bool diagnoseAsError() override;
14421444

14431445
bool diagnoseForAnchor(Anchor anchor,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: not %target-swift-frontend -typecheck %s
2+
3+
public func trichotomy<T : Comparable>(x: T, y: T) -> some Comparable {
4+
if x < y { return -1 }
5+
else if x == y { return 0 }
6+
return 1
7+
}
8+
9+
public func myTri<T: Comparable, U: Comparable> (retval: UnsafeMutablePointer<U>, x: UnsafeMutablePointer<T>, y: UnsafeMutablePointer<T>) {
10+
retval.initialize(to: trichotomy(x: x, y: y))
11+
}
12+
13+
print("Hello, World!")

0 commit comments

Comments
 (0)