Skip to content

Commit 259b2e2

Browse files
committed
AST: More error-proof getContextSubstitutions()
The loop at the end is meant to fill in substitutions from the local context with corresponding context archetypes, but we can end up here if the getSuperclassForDecl() class failed above. In this case, fill in the replacement types with ErrorType instead to avoid surfacing archetypes from the wrong environment.
1 parent 007fe96 commit 259b2e2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/AST/Type.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4886,11 +4886,15 @@ TypeBase::getContextSubstitutions(const DeclContext *dc,
48864886
break;
48874887
}
48884888

4889+
// Add any outer generic parameters from the local context.
48894890
while (n > 0) {
48904891
auto *gp = params[--n];
4891-
auto substTy = (genericEnv
4892-
? genericEnv->mapTypeIntoContext(gp)
4893-
: gp);
4892+
Type substTy = gp;
4893+
if (baseTy && baseTy->is<ErrorType>())
4894+
substTy = ErrorType::get(baseTy->getASTContext());
4895+
else if (genericEnv)
4896+
substTy = genericEnv->mapTypeIntoContext(gp);
4897+
48944898
auto result = substitutions.insert(
48954899
{gp->getCanonicalType()->castTo<GenericTypeParamType>(),
48964900
substTy});

0 commit comments

Comments
 (0)