Skip to content

Commit 0304f41

Browse files
authored
Merge pull request #26904 from xedin/rdar-52774804-5.1
[5.1][Diagnostics] Don't crash trying to diagnose missing opaque result type
2 parents 93d25c1 + d2c9fe0 commit 0304f41

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2959,6 +2959,9 @@ bool MissingGenericArgumentsFailure::diagnoseForAnchor(
29592959
return false;
29602960

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

3011-
if (!hasLoc(GP))
3012-
return true;
3013-
30143014
Type baseTyForNote;
30153015
auto *DC = getDeclContext();
3016+
if (!DC)
3017+
return true;
3018+
3019+
if (!hasLoc(GP))
3020+
return true;
30163021

30173022
if (auto *NTD =
30183023
dyn_cast_or_null<NominalTypeDecl>(DC->getSelfNominalTypeDecl())) {
@@ -3034,6 +3039,9 @@ void MissingGenericArgumentsFailure::emitGenericSignatureNote(
30343039
auto &TC = getTypeChecker();
30353040
auto *paramDC = getDeclContext();
30363041

3042+
if (!paramDC)
3043+
return;
3044+
30373045
auto *GTD = dyn_cast<GenericTypeDecl>(paramDC);
30383046
if (!GTD || anchor.is<Expr *>())
30393047
return;

lib/Sema/CSDiagnostics.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,9 @@ class MissingGenericArgumentsFailure final : public FailureDiagnostic {
13341334

13351335
DeclContext *getDeclContext() const {
13361336
auto *GP = Parameters.front();
1337-
return GP->getDecl()->getDeclContext();
1337+
auto *decl = GP->getDecl();
1338+
1339+
return decl ? decl->getDeclContext() : nullptr;
13381340
}
13391341

13401342
bool diagnoseAsError() override;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+

0 commit comments

Comments
 (0)