Skip to content

Commit d602cdf

Browse files
committed
[TypeChecker] NFC: Add more tests to keypath dynamic member lookup (tuple access + subscript/property combo)
1 parent 41f6eb9 commit d602cdf

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

test/attr/attr_dynamic_member_lookup.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,14 @@ acceptKeyPathDynamicLookup(lens.topLeft.x)
456456
acceptKeyPathDynamicLookup(lens.topLeft.y)
457457
acceptKeyPathDynamicLookup(lens.topLeft.z) // expected-error {{'z' is inaccessible due to 'private' protection level}}
458458

459+
var tupleLens = Lens<(String, Int)>(("ultimate question", 42))
460+
_ = tupleLens.0.count
461+
_ = tupleLens.1
462+
463+
var namedTupleLens = Lens<(question: String, answer: Int)>((question: "ultimate question", answer: 42))
464+
_ = namedTupleLens.question.count
465+
_ = namedTupleLens.answer
466+
459467
@dynamicMemberLookup
460468
class A<T> {
461469
var value: T
@@ -607,3 +615,11 @@ func keypath_with_trailing_closure_subscript(_ ty: inout SubscriptLens<WithTrail
607615
_ = ty[] { 42 } // expected-error {{subscript index of type '() -> Int' in a key path must be Hashable}}
608616
_ = ty[] { 42 } = 0 // expected-error {{subscript index of type '() -> Int' in a key path must be Hashable}}
609617
}
618+
619+
func keypath_to_subscript_to_property(_ lens: inout Lens<Array<Rectangle>>) {
620+
_ = lens[0].topLeft.x
621+
_ = lens[0].topLeft.y
622+
_ = lens[0].topLeft.x = Lens(0)
623+
_ = lens[0].topLeft.y = Lens(1) // FIXME(diagnostics): Diagnostic should point to 'y' instead of 'lens'
624+
// expected-error@-1 {{cannot assign through dynamic lookup property: 'lens' is immutable}}
625+
}

0 commit comments

Comments
 (0)