Skip to content

Commit a7988b0

Browse files
committed
[Diagnostics] Make sure extension type repr is available before using it
Before suggesting to add `where Self == ...` condition to the extension of a protocol involved in a static member lookup, let's check whether type repr is available and valid. Resolves: rdar://78097387
1 parent e8d1a16 commit a7988b0

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7432,9 +7432,15 @@ bool InvalidMemberRefOnProtocolMetatype::diagnoseAsError() {
74327432
if (auto *whereClause = extension->getTrailingWhereClause()) {
74337433
auto sourceRange = whereClause->getSourceRange();
74347434
note.fixItInsertAfter(sourceRange.End, ", Self == <#Type#> ");
7435-
} else {
7436-
auto nameRepr = extension->getExtendedTypeRepr();
7437-
note.fixItInsertAfter(nameRepr->getEndLoc(), " where Self == <#Type#>");
7435+
} else if (auto nameRepr = extension->getExtendedTypeRepr()) {
7436+
// Type repr is not always available so we need to be defensive
7437+
// about its presence and validity.
7438+
if (nameRepr->isInvalid()))
7439+
return true;
7440+
7441+
if (auto noteLoc = nameRepr->getEndLoc()) {
7442+
note.fixItInsertAfter(noteLoc, " where Self == <#Type#>");
7443+
}
74387444
}
74397445

74407446
return true;

0 commit comments

Comments
 (0)