Skip to content

Commit f018328

Browse files
committed
[TypeResolver] Fix a few corner cases in type resolution for explicit
existential types. Use the correct type resolver context when resolving SIL metatypes and function types, and diagnose an error if an explicit existential type appears in a protocol composition.
1 parent 5dced8e commit f018328

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,7 +2274,13 @@ TypeResolver::resolveAttributedType(TypeAttributes &attrs, TypeRepr *repr,
22742274
Optional<MetatypeRepresentation> storedRepr;
22752275
// The instance type is not a SIL type.
22762276
auto instanceOptions = options;
2277-
instanceOptions.setContext(None);
2277+
TypeResolverContext context = TypeResolverContext::None;
2278+
if (isa<MetatypeTypeRepr>(repr)) {
2279+
context = TypeResolverContext::MetatypeBase;
2280+
} else if (isa<ProtocolTypeRepr>(repr)) {
2281+
context = TypeResolverContext::ProtocolMetatypeBase;
2282+
}
2283+
instanceOptions.setContext(context);
22782284
instanceOptions -= TypeResolutionFlags::SILType;
22792285

22802286
auto instanceTy = resolveType(base, instanceOptions);
@@ -3166,7 +3172,8 @@ NeverNullType TypeResolver::resolveSILFunctionType(
31663172

31673173
ProtocolConformanceRef witnessMethodConformance;
31683174
if (witnessMethodProtocol) {
3169-
auto resolved = resolveType(witnessMethodProtocol, options);
3175+
auto resolved = resolveType(witnessMethodProtocol,
3176+
options.withContext(TypeResolverContext::GenericRequirement));
31703177
if (resolved->hasError())
31713178
return resolved;
31723179

@@ -3443,9 +3450,7 @@ TypeResolver::resolveIdentifierType(IdentTypeRepr *IdType,
34433450
}
34443451

34453452
// FIXME: Don't use ExistentialType for AnyObject for now.
3446-
bool isConstraintType = (result->is<ProtocolType>() &&
3447-
!result->isAnyObject());
3448-
if (isConstraintType &&
3453+
if (result->isConstraintType() && !result->isAnyObject() &&
34493454
getASTContext().LangOpts.EnableExplicitExistentialTypes &&
34503455
options.isConstraintImplicitExistential()) {
34513456
return ExistentialType::get(result);
@@ -3807,7 +3812,7 @@ TypeResolver::resolveCompositionType(CompositionTypeRepr *repr,
38073812
continue;
38083813
}
38093814

3810-
if (ty->isExistentialType()) {
3815+
if (ty->isConstraintType()) {
38113816
auto layout = ty->getExistentialLayout();
38123817
if (auto superclass = layout.explicitSuperclass)
38133818
if (checkSuperclass(tyR->getStartLoc(), superclass))

0 commit comments

Comments
 (0)