From 61f03f8612062856b0395e8df8b9ba291d879aa5 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Wed, 13 Apr 2022 17:06:21 -0700 Subject: [PATCH] Turn on Existential Metatypes These were accidentally left off - turn them on subject to the -enable-parameterized-existential-types flag. --- lib/Sema/TypeCheckType.h | 2 +- .../parameterized_existential_metatypes.swift | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/Constraints/parameterized_existential_metatypes.swift 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