Skip to content

Commit 317c031

Browse files
committed
AST: Cope with invalid inputs better in ExtensionDecl::isConstrainedExtension()
1 parent 7bebb00 commit 317c031

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/AST/Decl.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,16 +1221,21 @@ bool ExtensionDecl::hasValidParent() const {
12211221
}
12221222

12231223
bool ExtensionDecl::isConstrainedExtension() const {
1224-
// Non-generic extension.
1225-
if (!getGenericSignature())
1224+
auto nominal = getExtendedNominal();
1225+
if (!nominal)
12261226
return false;
12271227

1228-
auto nominal = getExtendedNominal();
1229-
assert(nominal);
1228+
auto typeSig = nominal->getGenericSignature();
1229+
if (!typeSig)
1230+
return false;
1231+
1232+
auto extSig = getGenericSignature();
1233+
if (!extSig)
1234+
return false;
12301235

12311236
// If the generic signature differs from that of the nominal type, it's a
12321237
// constrained extension.
1233-
return !getGenericSignature()->isEqual(nominal->getGenericSignature());
1238+
return !typeSig->isEqual(extSig);
12341239
}
12351240

12361241
bool ExtensionDecl::isEquivalentToExtendedContext() const {

0 commit comments

Comments
 (0)