@@ -227,18 +227,18 @@ func test_keypath_dynamic_lookup_inside_keypath() {
227
227
_ = \Lens < [ [ Int ] ] > . [ 0 ] . count
228
228
}
229
229
230
- func test_recursive_dynamic_lookup( _ lens : Lens < Lens < Point > > ) {
230
+ func test_recursive_dynamic_lookup( _ pointLens : Lens < Lens < Point > > , _ arrLens : Lens < Lens < [ Point ] > > ) {
231
231
// CHECK: keypath $KeyPath<Point, Int>, (root $Point; stored_property #Point.x : $Int)
232
232
// CHECK-NEXT: keypath $KeyPath<Lens<Point>, Lens<Int>>, (root $Lens<Point>; gettable_property $Lens<Int>, id @$s29keypath_dynamic_member_lookup4LensV0B6MemberACyqd__Gs7KeyPathCyxqd__G_tcluig : {{.*}})
233
233
// CHECK: function_ref @$s29keypath_dynamic_member_lookup4LensV0B6MemberACyqd__Gs7KeyPathCyxqd__G_tcluig
234
- _ = lens . x
234
+ _ = pointLens . x
235
235
// CHECK: keypath $KeyPath<Point, Int>, (root $Point; stored_property #Point.x : $Int)
236
236
// CHECK: function_ref @$s29keypath_dynamic_member_lookup4LensV0B6MemberACyqd__Gs7KeyPathCyxqd__G_tcluig
237
- _ = lens . obj. x
237
+ _ = pointLens . obj. x
238
238
// CHECK: [[FIRST_OBJ:%.*]] = struct_extract {{.*}} : $Lens<Lens<Point>>, #Lens.obj
239
239
// CHECK-NEXT: [[SECOND_OBJ:%.*]] = struct_extract [[FIRST_OBJ]] : $Lens<Point>, #Lens.obj
240
240
// CHECK-NEXT: struct_extract [[SECOND_OBJ]] : $Point, #Point.y
241
- _ = lens . obj. obj. y
241
+ _ = pointLens . obj. obj. y
242
242
// CHECK: keypath $KeyPath<Point, Int>, (root $Point; stored_property #Point.x : $Int)
243
243
// CHECK-NEXT: keypath $KeyPath<Lens<Point>, Lens<Int>>, (root $Lens<Point>; gettable_property $Lens<Int>, id @$s29keypath_dynamic_member_lookup4LensV0B6MemberACyqd__Gs7KeyPathCyxqd__G_tcluig : {{.*}})
244
244
// CHECK-NEXT: keypath $KeyPath<Lens<Lens<Point>>, Lens<Lens<Int>>>, (root $Lens<Lens<Point>>; gettable_property $Lens<Lens<Int>>, id @$s29keypath_dynamic_member_lookup4LensV0B6MemberACyqd__Gs7KeyPathCyxqd__G_tcluig : {{.*}})
@@ -249,6 +249,21 @@ func test_recursive_dynamic_lookup(_ lens: Lens<Lens<Point>>) {
249
249
// CHECK-NEXT: keypath $KeyPath<Lens<Point>, Lens<Int>>, (root $Lens<Point>; gettable_property $Lens<Int>, id @$s29keypath_dynamic_member_lookup4LensV0B6MemberACyqd__Gs7KeyPathCyxqd__G_tcluig : {{.*}})
250
250
// CHECK-NEXT: keypath $KeyPath<Lens<Lens<Rectangle>>, Lens<Lens<Int>>>, (root $Lens<Lens<Rectangle>>; settable_property $Lens<Lens<Point>>, id @$s29keypath_dynamic_member_lookup4LensV0B6MemberACyqd__Gs15WritableKeyPathCyxqd__G_tcluig : {{.*}})
251
251
_ = \Lens < Lens < Rectangle > > . topLeft. x
252
+
253
+ // CHECK: keypath $WritableKeyPath<Array<Point>, Point>, (root $Array<Point>; settable_property $Point, id @$sSayxSicig
254
+ // CHECK-NEXT: keypath $WritableKeyPath<Lens<Array<Point>>, Lens<Point>>, (root $Lens<Array<Point>>; settable_property $Lens<Point>, id @$s29keypath_dynamic_member_lookup4LensV0B6MemberACyqd__Gs15WritableKeyPathCyxqd__G_tcluig
255
+ // CHECK: function_ref @$s29keypath_dynamic_member_lookup4LensV0B6MemberACyqd__Gs15WritableKeyPathCyxqd__G_tcluig
256
+ // CHECK: keypath $KeyPath<Point, Int>, (root $Point; stored_property #Point.x : $Int)
257
+ // CHECK-NEXT: keypath $KeyPath<Lens<Point>, Lens<Int>>, (root $Lens<Point>; gettable_property $Lens<Int>, id @$s29keypath_dynamic_member_lookup4LensV0B6MemberACyqd__Gs7KeyPathCyxqd__G_tcluig
258
+ // CHECK: function_ref @$s29keypath_dynamic_member_lookup4LensV0B6MemberACyqd__Gs7KeyPathCyxqd__G_tcluig
259
+ _ = arrLens [ 0 ] . x // arrLens[dynamicMember: \.[dynamicMember: \.[0]]][dynamicMember: \.[dynamicMember: \.x]]
260
+
261
+ _ = \Lens < Lens < [ Point ] > > . [ 0 ] . x // \Lens<Lens<[Point]>>.[dynamicMember: \.[dynamicMember: \.[0]]].[dynamicMember: \.[dynamicMember: \.x]]
262
+ // CHECK: keypath $WritableKeyPath<Array<Point>, Point>, (root $Array<Point>; settable_property $Point, id @$sSayxSicig
263
+ // CHECK-NEXT: keypath $WritableKeyPath<Lens<Array<Point>>, Lens<Point>>, (root $Lens<Array<Point>>; settable_property $Lens<Point>, id @$s29keypath_dynamic_member_lookup4LensV0B6MemberACyqd__Gs15WritableKeyPathCyxqd__G_tcluig
264
+ // CHECK-NEXT: keypath $KeyPath<Point, Int>, (root $Point; stored_property #Point.x : $Int)
265
+ // CHECK-NEXT: keypath $KeyPath<Lens<Point>, Lens<Int>>, (root $Lens<Point>; gettable_property $Lens<Int>, id @$s29keypath_dynamic_member_lookup4LensV0B6MemberACyqd__Gs7KeyPathCyxqd__G_tcluig
266
+ // CHECK-NEXT: keypath $KeyPath<Lens<Lens<Array<Point>>>, Lens<Lens<Int>>>, (root $Lens<Lens<Array<Point>>>; settable_property $Lens<Lens<Point>>, id @$s29keypath_dynamic_member_lookup4LensV0B6MemberACyqd__Gs15WritableKeyPathCyxqd__G_tcluig
252
267
}
253
268
254
269
@dynamicMemberLookup
@@ -558,3 +573,31 @@ struct S_54150 {
558
573
// CHECK-NEXT: apply %{{.*}}<S_54150, T>({{.*}})
559
574
}
560
575
}
576
+
577
+ // https://github.com/swiftlang/swift/issues/56837
578
+ @dynamicMemberLookup
579
+ struct Issue56837 < Value, Integer: FixedWidthInteger > {
580
+ var value : Value
581
+ init ( _ value: Value ) {
582
+ self . value = value
583
+ }
584
+ subscript< T> ( dynamicMember keyPath: KeyPath < Value , T > ) -> T {
585
+ get { return self . value [ keyPath: keyPath] }
586
+ }
587
+ subscript( type value: Integer ) -> Bool {
588
+ get { return true }
589
+ }
590
+ }
591
+ struct TestIssue56837 {
592
+ typealias T1 = Issue56837 < String , Int8 >
593
+ typealias T2 = Issue56837 < T1 , Int16 >
594
+ typealias T3 = Issue56837 < T2 , Int32 >
595
+ typealias T4 = Issue56837 < T3 , Int64 >
596
+ static func test( ) {
597
+ let value : T4 = . init( . init( . init( . init( " Swift " ) ) ) )
598
+ _ = value [ type: Int64 . max]
599
+ _ = value [ type: Int32 . max]
600
+ _ = value [ type: Int16 . max]
601
+ _ = value [ type: Int8 . max]
602
+ }
603
+ }
0 commit comments