Skip to content

Commit 2339b5f

Browse files
committed
[CSDiagnostics] Move check inside getDeclContext()
1 parent e50050b commit 2339b5f

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
@@ -3280,10 +3280,10 @@ bool MissingGenericArgumentsFailure::diagnoseForAnchor(
32803280
if (!diagnosed)
32813281
return false;
32823282

3283-
if (!hasDecl())
3283+
auto *DC = getDeclContext();
3284+
if (!DC)
32843285
return true;
32853286

3286-
auto *DC = getDeclContext();
32873287
if (auto *SD = dyn_cast<SubscriptDecl>(DC)) {
32883288
emitDiagnostic(SD, diag::note_call_to_subscript, SD->getFullName());
32893289
return true;
@@ -3333,15 +3333,14 @@ bool MissingGenericArgumentsFailure::diagnoseParameter(
33333333
emitDiagnostic(loc, diag::unbound_generic_parameter, GP);
33343334
}
33353335

3336-
if (!hasDecl())
3336+
Type baseTyForNote;
3337+
auto *DC = getDeclContext();
3338+
if (!DC)
33373339
return true;
33383340

33393341
if (!hasLoc(GP))
33403342
return true;
33413343

3342-
Type baseTyForNote;
3343-
auto *DC = getDeclContext();
3344-
33453344
if (auto *NTD =
33463345
dyn_cast_or_null<NominalTypeDecl>(DC->getSelfNominalTypeDecl())) {
33473346
baseTyForNote = NTD->getDeclaredType();
@@ -3362,6 +3361,9 @@ void MissingGenericArgumentsFailure::emitGenericSignatureNote(
33623361
auto &TC = getTypeChecker();
33633362
auto *paramDC = getDeclContext();
33643363

3364+
if (!paramDC)
3365+
return;
3366+
33653367
auto *GTD = dyn_cast<GenericTypeDecl>(paramDC);
33663368
if (!GTD || anchor.is<Expr *>())
33673369
return;

lib/Sema/CSDiagnostics.h

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

14361436
DeclContext *getDeclContext() const {
14371437
auto *GP = Parameters.front();
1438-
return GP->getDecl()->getDeclContext();
1439-
}
1438+
auto *decl = GP->getDecl();
14401439

1441-
bool hasDecl() const { return Parameters.front()->getDecl() != nullptr; }
1440+
return decl ? decl->getDeclContext() : nullptr;
1441+
}
14421442

14431443
bool diagnoseAsError() override;
14441444

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)