Skip to content

Commit

Permalink
[Constraint solver] Fix backward trailing closures with ".member" exp…
Browse files Browse the repository at this point in the history
…ressions

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.
  • Loading branch information
DougGregor committed Aug 31, 2020
1 parent 6ad2757 commit 0b2b7b5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5592,7 +5592,9 @@ Expr *ExprRewriter::coerceCallArguments(
SmallVector<LocatorPathElt, 4> path;
auto anchor = locator.getLocatorParts(path);
if (!path.empty() && path.back().is<LocatorPathElt::ApplyArgument>() &&
(anchor.isExpr(ExprKind::Call) || anchor.isExpr(ExprKind::Subscript))) {
(anchor.isExpr(ExprKind::Call) ||
anchor.isExpr(ExprKind::Subscript) ||
anchor.isExpr(ExprKind::UnresolvedMember))) {
auto locatorPtr = cs.getConstraintLocator(locator);
assert(solution.trailingClosureMatchingChoices.count(locatorPtr) == 1);
trailingClosureMatching = solution.trailingClosureMatchingChoices.find(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// RUN: %target-swift-emit-silgen %s | %FileCheck %s

// rdar://problem/67781123 - crash in SILGen

struct Foo {
var title: String
var handler1: ((Int, String) -> Void)?
var handler2: (() -> Void)?
}

func take(foo: Foo) { }

// CHECK-LABEL: sil hidden [ossa] @$s42forward_trailing_closure_unresolved_member4testyy
func test() {
// CHECK: function_ref @$s42forward_trailing_closure_unresolved_member4testyyFyycfU_ : $@convention(thin) () -> ()
take(foo: .init(title: "") {
print("handler2 is called")
})
}

0 comments on commit 0b2b7b5

Please sign in to comment.