Skip to content

Commit 0b2b7b5

Browse files
committed
[Constraint solver] Fix backward trailing closures with ".member" expressions
The introduction of forward-scan matching for trailing closures (SE-0286) failed to account for unresolved member expressions, sometimes causing a crash in SILGen. Fixes rdar://problem/67781123.
1 parent 6ad2757 commit 0b2b7b5

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/Sema/CSApply.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5592,7 +5592,9 @@ Expr *ExprRewriter::coerceCallArguments(
55925592
SmallVector<LocatorPathElt, 4> path;
55935593
auto anchor = locator.getLocatorParts(path);
55945594
if (!path.empty() && path.back().is<LocatorPathElt::ApplyArgument>() &&
5595-
(anchor.isExpr(ExprKind::Call) || anchor.isExpr(ExprKind::Subscript))) {
5595+
(anchor.isExpr(ExprKind::Call) ||
5596+
anchor.isExpr(ExprKind::Subscript) ||
5597+
anchor.isExpr(ExprKind::UnresolvedMember))) {
55965598
auto locatorPtr = cs.getConstraintLocator(locator);
55975599
assert(solution.trailingClosureMatchingChoices.count(locatorPtr) == 1);
55985600
trailingClosureMatching = solution.trailingClosureMatchingChoices.find(
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-swift-emit-silgen %s | %FileCheck %s
2+
3+
// rdar://problem/67781123 - crash in SILGen
4+
5+
struct Foo {
6+
var title: String
7+
var handler1: ((Int, String) -> Void)?
8+
var handler2: (() -> Void)?
9+
}
10+
11+
func take(foo: Foo) { }
12+
13+
// CHECK-LABEL: sil hidden [ossa] @$s42forward_trailing_closure_unresolved_member4testyy
14+
func test() {
15+
// CHECK: function_ref @$s42forward_trailing_closure_unresolved_member4testyyFyycfU_ : $@convention(thin) () -> ()
16+
take(foo: .init(title: "") {
17+
print("handler2 is called")
18+
})
19+
}

0 commit comments

Comments
 (0)