Skip to content

Commit c1b3d2d

Browse files
committed
[Sema] Make explicit that resolveInverseType doesn't look through parens
Check for `isParenType` on the TypeRepr to avoid relying on getting that behavior by casting the type pointer.
1 parent b4b99e9 commit c1b3d2d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5937,14 +5937,17 @@ NeverNullType TypeResolver::resolveInverseType(InverseTypeRepr *repr,
59375937
TypeResolutionOptions options) {
59385938
auto subOptions = options.withoutContext(true)
59395939
.withContext(TypeResolverContext::Inverted);
5940-
auto ty = resolveType(repr->getConstraint(), subOptions);
5940+
auto *constraintRepr = repr->getConstraint();
5941+
auto ty = resolveType(constraintRepr, subOptions);
59415942
if (ty->hasError())
59425943
return ErrorType::get(getASTContext());
59435944

59445945
// If the inverted type is an existential metatype, unwrap the existential
59455946
// metatype so we can look at the instance type. We'll re-wrap at the end.
5946-
ExistentialMetatypeType *existentialTy =
5947-
dyn_cast<ExistentialMetatypeType>(ty.get().getPointer());
5947+
// Note we don't look through parens.
5948+
ExistentialMetatypeType *existentialTy = nullptr;
5949+
if (!constraintRepr->isParenType())
5950+
existentialTy = dyn_cast<ExistentialMetatypeType>(ty.get().getPointer());
59485951
if (existentialTy) {
59495952
ty = existentialTy->getInstanceType();
59505953
}

0 commit comments

Comments
 (0)