Skip to content

Commit d2c9fe0

Browse files
theblixguyxedin
authored andcommitted
[CSDiagnostics] Move check inside getDeclContext()
(cherry picked from commit 2339b5f)
1 parent f096cf0 commit d2c9fe0

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2958,10 +2958,10 @@ bool MissingGenericArgumentsFailure::diagnoseForAnchor(
29582958
if (!diagnosed)
29592959
return false;
29602960

2961-
if (!hasDecl())
2961+
auto *DC = getDeclContext();
2962+
if (!DC)
29622963
return true;
29632964

2964-
auto *DC = getDeclContext();
29652965
if (auto *SD = dyn_cast<SubscriptDecl>(DC)) {
29662966
emitDiagnostic(SD, diag::note_call_to_subscript, SD->getFullName());
29672967
return true;
@@ -3011,15 +3011,14 @@ bool MissingGenericArgumentsFailure::diagnoseParameter(
30113011
emitDiagnostic(loc, diag::unbound_generic_parameter, GP);
30123012
}
30133013

3014-
if (!hasDecl())
3014+
Type baseTyForNote;
3015+
auto *DC = getDeclContext();
3016+
if (!DC)
30153017
return true;
30163018

30173019
if (!hasLoc(GP))
30183020
return true;
30193021

3020-
Type baseTyForNote;
3021-
auto *DC = getDeclContext();
3022-
30233022
if (auto *NTD =
30243023
dyn_cast_or_null<NominalTypeDecl>(DC->getSelfNominalTypeDecl())) {
30253024
baseTyForNote = NTD->getDeclaredType();
@@ -3040,6 +3039,9 @@ void MissingGenericArgumentsFailure::emitGenericSignatureNote(
30403039
auto &TC = getTypeChecker();
30413040
auto *paramDC = getDeclContext();
30423041

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

lib/Sema/CSDiagnostics.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,10 +1334,10 @@ class MissingGenericArgumentsFailure final : public FailureDiagnostic {
13341334

13351335
DeclContext *getDeclContext() const {
13361336
auto *GP = Parameters.front();
1337-
return GP->getDecl()->getDeclContext();
1338-
}
1337+
auto *decl = GP->getDecl();
13391338

1340-
bool hasDecl() const { return Parameters.front()->getDecl() != nullptr; }
1339+
return decl ? decl->getDeclContext() : nullptr;
1340+
}
13411341

13421342
bool diagnoseAsError() override;
13431343

validation-test/compiler_crashers_2_fixed/sr11236.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@ public func myTri<T: Comparable, U: Comparable> (retval: UnsafeMutablePointer<U>
1010
retval.initialize(to: trichotomy(x: x, y: y))
1111
}
1212

13-
print("Hello, World!")

0 commit comments

Comments
 (0)