Don't open existential arguments to type(of:).

This commit is contained in:
Doug Gregor
2022-02-07 16:11:21 -08:00
parent 1273fa4185
commit deab0b9bd7
2 changed files with 11 additions and 3 deletions

View File

@@ -1338,11 +1338,18 @@ shouldOpenExistentialCallArgument(
if (!callee)
return None;
// _openExistential handles its own opening.
if (TypeChecker::getDeclTypeCheckingSemantics(callee) ==
DeclTypeCheckingSemantics::OpenExistential)
// Special semantics prohibit opening existentials.
switch (TypeChecker::getDeclTypeCheckingSemantics(callee)) {
case DeclTypeCheckingSemantics::OpenExistential:
case DeclTypeCheckingSemantics::TypeOf:
// type(of:) and _openExistential handle their own opening.
return None;
case DeclTypeCheckingSemantics::Normal:
case DeclTypeCheckingSemantics::WithoutActuallyEscaping:
break;
}
ASTContext &ctx = callee->getASTContext();
if (!ctx.LangOpts.EnableOpenedExistentialTypes)
return None;

View File

@@ -1,4 +1,5 @@
// RUN: %target-typecheck-verify-swift
// RUN: %target-typecheck-verify-swift -enable-experimental-opened-existential-types
protocol P { }