Skip to content

Commit 675c5f4

Browse files
committed
[TypeChecker] Add subscript + trailing closure tests for keypath dynamic member lookup
1 parent 99c27d2 commit 675c5f4

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1573,7 +1573,7 @@ namespace {
15731573

15741574
Expr *trailingClosure = nullptr;
15751575
if (SE->hasTrailingClosure())
1576-
trailingClosure = arguments.pop_back_val();
1576+
trailingClosure = arguments.back();
15771577

15781578
componentExpr = SubscriptExpr::create(
15791579
ctx, dotExpr, SE->getStartLoc(), arguments, SE->getArgumentLabels(),

test/attr/attr_dynamic_member_lookup.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,3 +587,20 @@ func keypath_with_incorrect_return_type(_ arr: Lens<Array<Int>>) {
587587
let _ = arr[idx]
588588
}
589589
}
590+
591+
struct WithTrailingClosure {
592+
subscript(fn: () -> Int) -> Int {
593+
get { return fn() }
594+
nonmutating set { _ = fn() + newValue }
595+
}
596+
597+
subscript(offset: Int, _ fn: () -> Int) -> Int {
598+
get { return offset + fn() }
599+
}
600+
}
601+
602+
func keypath_with_trailing_closure_subscript(_ ty: inout SubscriptLens<WithTrailingClosure>) {
603+
_ = ty[0] { 42 } // expected-error {{subscript index of type '() -> Int' in a key path must be Hashable}}
604+
_ = ty[] { 42 } // expected-error {{subscript index of type '() -> Int' in a key path must be Hashable}}
605+
_ = ty[] { 42 } = 0 // expected-error {{subscript index of type '() -> Int' in a key path must be Hashable}}
606+
}

0 commit comments

Comments
 (0)