Skip to content

Commit f096cf0

Browse files
theblixguyxedin
authored andcommitted
[CSDiagnostics] Don't crash if we don't have access to the generic param's decl
(cherry picked from commit e50050b)
1 parent e90298c commit f096cf0

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
@@ -2958,6 +2958,9 @@ bool MissingGenericArgumentsFailure::diagnoseForAnchor(
29582958
if (!diagnosed)
29592959
return false;
29602960

2961+
if (!hasDecl())
2962+
return true;
2963+
29612964
auto *DC = getDeclContext();
29622965
if (auto *SD = dyn_cast<SubscriptDecl>(DC)) {
29632966
emitDiagnostic(SD, diag::note_call_to_subscript, SD->getFullName());
@@ -3008,6 +3011,9 @@ bool MissingGenericArgumentsFailure::diagnoseParameter(
30083011
emitDiagnostic(loc, diag::unbound_generic_parameter, GP);
30093012
}
30103013

3014+
if (!hasDecl())
3015+
return true;
3016+
30113017
if (!hasLoc(GP))
30123018
return true;
30133019

lib/Sema/CSDiagnostics.h

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

1340+
bool hasDecl() const { return Parameters.front()->getDecl() != nullptr; }
1341+
13401342
bool diagnoseAsError() override;
13411343

13421344
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)