Skip to content

Commit deab0b9

Browse files
committed
Don't open existential arguments to type(of:).
1 parent 1273fa4 commit deab0b9

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,11 +1338,18 @@ shouldOpenExistentialCallArgument(
13381338
if (!callee)
13391339
return None;
13401340

1341-
// _openExistential handles its own opening.
1342-
if (TypeChecker::getDeclTypeCheckingSemantics(callee) ==
1343-
DeclTypeCheckingSemantics::OpenExistential)
1341+
// Special semantics prohibit opening existentials.
1342+
switch (TypeChecker::getDeclTypeCheckingSemantics(callee)) {
1343+
case DeclTypeCheckingSemantics::OpenExistential:
1344+
case DeclTypeCheckingSemantics::TypeOf:
1345+
// type(of:) and _openExistential handle their own opening.
13441346
return None;
13451347

1348+
case DeclTypeCheckingSemantics::Normal:
1349+
case DeclTypeCheckingSemantics::WithoutActuallyEscaping:
1350+
break;
1351+
}
1352+
13461353
ASTContext &ctx = callee->getASTContext();
13471354
if (!ctx.LangOpts.EnableOpenedExistentialTypes)
13481355
return None;

test/Constraints/openExistential.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-typecheck-verify-swift
2+
// RUN: %target-typecheck-verify-swift -enable-experimental-opened-existential-types
23

34
protocol P { }
45

0 commit comments

Comments
 (0)