File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed
Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -7802,9 +7802,10 @@ ConstraintSystem::simplifyKeyPathApplicationConstraint(
78027802 return SolutionKind::Unsolved;
78037803 };
78047804
7805- // When locator points to a KeyPathDynamicMemberLookup, skip the
7805+ // When locator points to a KeyPathDynamicMemberLookup, reject the
78067806 // key path application.
7807- if (locator.getBaseLocator ()->isForKeyPathDynamicMemberLookup ()) {
7807+ auto last = locator.last ();
7808+ if (last && last->isKeyPathDynamicMember ()) {
78087809 return SolutionKind::Error;
78097810 }
78107811
Original file line number Diff line number Diff line change @@ -789,3 +789,31 @@ func test_combination_of_keypath_and_string_lookups() {
789789 _ = outer. hello. world // Ok
790790 }
791791}
792+
793+ // SR-12626
794+ @dynamicMemberLookup
795+ struct SR12626 {
796+ var i : Int
797+
798+ subscript( dynamicMember member: KeyPath < SR12626 , Int > ) -> Int {
799+ get { self [ keyPath: member] }
800+ set { self [ keyPath: member] = newValue } // expected-error {{cannot assign through subscript: 'member' is a read-only key path}}
801+ }
802+ }
803+
804+ // SR-12245
805+ public struct SR12425_S { }
806+
807+ @dynamicMemberLookup
808+ public struct SR12425_R { }
809+
810+ internal var rightStructInstance : SR12425_R = SR12425_R ( )
811+
812+ public extension SR12425_R {
813+ subscript< T> ( dynamicMember member: WritableKeyPath < SR12425_S , T > ) -> T {
814+ // TODO(Diagnostics): bad diagnostic for member assign.
815+ // A better diagnostic would be: key path of type WritableKeyPath<SR12425_S, T> cannot be applied to a base of type SR12425_R
816+ get { rightStructInstance [ keyPath: member] } // expected-error {{cannot convert return expression of type 'Any?' to return type 'T'}}
817+ set { rightStructInstance [ keyPath: member] = newValue } // expected-error {{type of expression is ambiguous without more context}}
818+ }
819+ }
You can’t perform that action at this time.
0 commit comments