Skip to content

Commit 3af5e70

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 (cherry picked from commit a7988b0)
1 parent 1666c2b commit 3af5e70

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
@@ -7433,9 +7433,15 @@ bool InvalidMemberRefOnProtocolMetatype::diagnoseAsError() {
74337433
if (auto *whereClause = extension->getTrailingWhereClause()) {
74347434
auto sourceRange = whereClause->getSourceRange();
74357435
note.fixItInsertAfter(sourceRange.End, ", Self == <#Type#> ");
7436-
} else {
7437-
auto nameRepr = extension->getExtendedTypeRepr();
7438-
note.fixItInsertAfter(nameRepr->getEndLoc(), " where Self == <#Type#>");
7436+
} else if (auto nameRepr = extension->getExtendedTypeRepr()) {
7437+
// Type repr is not always available so we need to be defensive
7438+
// about its presence and validity.
7439+
if (nameRepr->isInvalid())
7440+
return true;
7441+
7442+
if (auto noteLoc = nameRepr->getEndLoc()) {
7443+
note.fixItInsertAfter(noteLoc, " where Self == <#Type#>");
7444+
}
74397445
}
74407446

74417447
return true;

0 commit comments

Comments
 (0)