Skip to content

Commit 6ef2057

Browse files
authored
Merge pull request #37887 from xedin/rdar-78097387
[Diagnostics] Make sure extension type repr is available before using it
2 parents cda0330 + 7089b35 commit 6ef2057

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

include/swift/AST/Decl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,9 @@ class ExtensionDecl final : public GenericContext, public Decl,
13151315
bool alreadyBoundToNominal() const { return NextExtension.getInt(); }
13161316

13171317
/// Retrieve the extended type definition as written in the source, if it exists.
1318+
///
1319+
/// Repr would not be available if the extension was been loaded
1320+
/// from a serialized module.
13181321
TypeRepr *getExtendedTypeRepr() const { return ExtendedTypeRepr; }
13191322

13201323
/// Retrieve the set of protocols that this type inherits (i.e,

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)