Skip to content

Commit e3fc308

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 0d10a45 commit e3fc308

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
@@ -5881,14 +5881,17 @@ NeverNullType TypeResolver::resolveInverseType(InverseTypeRepr *repr,
58815881
TypeResolutionOptions options) {
58825882
auto subOptions = options.withoutContext(true)
58835883
.withContext(TypeResolverContext::Inverted);
5884-
auto ty = resolveType(repr->getConstraint(), subOptions);
5884+
auto *constraintRepr = repr->getConstraint();
5885+
auto ty = resolveType(constraintRepr, subOptions);
58855886
if (ty->hasError())
58865887
return ErrorType::get(getASTContext());
58875888

58885889
// If the inverted type is an existential metatype, unwrap the existential
58895890
// metatype so we can look at the instance type. We'll re-wrap at the end.
5890-
ExistentialMetatypeType *existentialTy =
5891-
dyn_cast<ExistentialMetatypeType>(ty.get().getPointer());
5891+
// Note we don't look through parens.
5892+
ExistentialMetatypeType *existentialTy = nullptr;
5893+
if (!constraintRepr->isParenType())
5894+
existentialTy = dyn_cast<ExistentialMetatypeType>(ty.get().getPointer());
58925895
if (existentialTy) {
58935896
ty = existentialTy->getInstanceType();
58945897
}

0 commit comments

Comments
 (0)