diff --git a/lib/Sema/TypeCheckType.h b/lib/Sema/TypeCheckType.h index 766b849686631..2cbbfe485ee56 100644 --- a/lib/Sema/TypeCheckType.h +++ b/lib/Sema/TypeCheckType.h @@ -288,11 +288,11 @@ class TypeResolutionOptions { case Context::GenericRequirement: return true; case Context::ExistentialConstraint: + case Context::MetatypeBase: return opts.EnableParameterizedExistentialTypes; case Context::None: case Context::TypeAliasDecl: case Context::GenericTypeAliasDecl: - case Context::MetatypeBase: case Context::InExpression: case Context::ExplicitCastExpr: case Context::ForEachStmt: diff --git a/test/Constraints/parameterized_existential_metatypes.swift b/test/Constraints/parameterized_existential_metatypes.swift new file mode 100644 index 0000000000000..40394685941bf --- /dev/null +++ b/test/Constraints/parameterized_existential_metatypes.swift @@ -0,0 +1,31 @@ +// RUN: %target-typecheck-verify-swift -enable-parameterized-existential-types +// +// FIXME: Merge this file with existential_metatypes.swift once -enable-parameterized-existential-types becomes the default + +protocol P { + associatedtype T +} + +protocol Q { + associatedtype T +} + +protocol PP: P { + associatedtype U: P +} + +var qp: (any Q).Type +var pp: (any P).Type = qp // expected-error{{cannot convert value of type '(any Q).Type' to specified type '(any P).Type'}} + +var qt: any Q.Type +qt = qp // expected-error{{cannot assign value of type '(any Q).Type' to type 'any Q.Type'}} +qp = qt // expected-error{{cannot assign value of type 'any Q.Type' to type '(any Q).Type'}} +var pt: any P.Type = qt // expected-error{{cannot convert value of type 'any Q.Type' to specified type 'any P.Type'}} +pt = pp // expected-error{{cannot assign value of type '(any P).Type' to type 'any P.Type'}} +pp = pt // expected-error{{cannot assign value of type 'any P.Type' to type '(any P).Type'}} + +var ppp: (any PP).Type +pp = ppp // expected-error{{cannot assign value of type '(any PP).Type' to type '(any P).Type'}} + +var ppt: any PP.Type +pt = ppt