Skip to content

Commit 4db1f7d

Browse files
committed
Map case variable types out of context.
Otherwise, we end up recording contextual types here.
1 parent b9f31a8 commit 4db1f7d

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

lib/Sema/BuilderTransform.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,8 @@ class BuilderClosureRewriter
15161516
for (auto *expected : caseStmt->getCaseBodyVariablesOrEmptyArray()) {
15171517
assert(expected->hasName());
15181518
auto prev = expected->getParentVarDecl();
1519-
auto type = solution.resolveInterfaceType(solution.getType(prev));
1519+
auto type = solution.resolveInterfaceType(
1520+
solution.getType(prev)->mapTypeOutOfContext());
15201521
expected->setInterfaceType(type);
15211522
}
15221523

lib/Sema/CSClosure.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,8 @@ class ClosureConstraintApplication
13491349
for (auto *expected : caseStmt->getCaseBodyVariablesOrEmptyArray()) {
13501350
assert(expected->hasName());
13511351
auto prev = expected->getParentVarDecl();
1352-
auto type = solution.resolveInterfaceType(solution.getType(prev));
1352+
auto type = solution.resolveInterfaceType(
1353+
solution.getType(prev)->mapTypeOutOfContext());
13531354
expected->setInterfaceType(type);
13541355
}
13551356

test/Constraints/closures.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,3 +1172,15 @@ func test(arr: [[Int]]) {
11721172
arr.map { ($0 as? [Int]).map { A($0) } } // expected-error {{missing argument label 'arg:' in call}} {{36-36=arg: }}
11731173
// expected-warning@-1 {{conditional cast from '[Int]' to '[Int]' always succeeds}}
11741174
}
1175+
1176+
func closureWithCaseArchetype<T>(_: T.Type) {
1177+
let _ = { (any: Any) throws -> Any? in
1178+
switch any {
1179+
case let type as T:
1180+
return type
1181+
1182+
default:
1183+
return any
1184+
}
1185+
}
1186+
}

0 commit comments

Comments
 (0)