@@ -524,16 +524,39 @@ func testInvalidKeyPathComponents() {
524
524
let _ = \. { return 0 } // expected-error* {{}}
525
525
}
526
526
527
+ struct W {
528
+ static let h = 50
529
+ }
530
+
527
531
class X {
528
532
class var a : Int { return 1 }
529
- static var b = 2
533
+ static var b = 20
534
+ let c = true
535
+ static subscript( d: Int ) -> String { " \( d) " }
536
+ var e : W . Type ? { return W . self }
537
+ }
538
+
539
+ class Y : X {
540
+ subscript( f: Int ) -> W . Type { W . self }
541
+ static subscript( g: Int ) -> W . Type { W . self }
530
542
}
531
543
532
544
func testStaticKeyPathComponent( ) {
533
- _ = \X . a // expected-error{{cannot refer to static member}}
534
- _ = \X . Type. a // expected-error{{cannot refer to static member}}
535
- _ = \X . b // expected-error{{cannot refer to static member}}
536
- _ = \X . Type. b // expected-error{{cannot refer to static member}}
545
+ _ = \X . a // expected-error{{static member 'a' cannot be used on instance of type 'X'}}
546
+ _ = \X . Type. a
547
+ _ = \X . b // expected-error{{static member 'b' cannot be used on instance of type 'X'}}
548
+ _ = \X . Type. b
549
+ _ = \X . c
550
+ _ = \X . Type. c // expected-error{{instance member 'c' cannot be used on type 'X'}}
551
+ _ = \X . [ 42 ] // expected-error{{static member 'subscript(_:)' cannot be used on instance of type 'X'}}
552
+ _ = \X . Type. [ 42 ]
553
+
554
+ let _: KeyPath < X , Int ? > = \. e? . h
555
+ let _: PartialKeyPath < X > = \. e? . h
556
+ let _: AnyKeyPath = \X . e? . h
557
+
558
+ let _ : KeyPath < Y , W . Type > = \Y . [ 40 ]
559
+ let _ : KeyPath < Y . Type , W . Type > = \Y . Type. [ 70 ]
537
560
}
538
561
539
562
class Bass : Hashable {
@@ -735,13 +758,13 @@ protocol P_With_Static_Members {
735
758
736
759
func test_keypath_with_static_members( _ p: P_With_Static_Members ) {
737
760
let _ = p [ keyPath: \. x]
738
- // expected-error@-1 {{key path cannot refer to static member 'x '}}
761
+ // expected-error@-1 {{static member 'x' cannot be used on instance of type 'any P_With_Static_Members '}}
739
762
let _: KeyPath < P_With_Static_Members , Int > = \. x
740
- // expected-error@-1 {{key path cannot refer to static member 'x '}}
763
+ // expected-error@-1 {{static member 'x' cannot be used on instance of type 'any P_With_Static_Members '}}
741
764
let _ = \P_With_Static_Members . arr. count
742
- // expected-error@-1 {{key path cannot refer to static member 'arr '}}
765
+ // expected-error@-1 {{static member 'arr' cannot be used on instance of type 'any P_With_Static_Members '}}
743
766
let _ = p [ keyPath: \. arr. count]
744
- // expected-error@-1 {{key path cannot refer to static member 'arr '}}
767
+ // expected-error@-1 {{static member 'arr' cannot be used on instance of type 'any P_With_Static_Members '}}
745
768
746
769
struct S {
747
770
static var foo : String = " Hello "
@@ -754,17 +777,16 @@ func test_keypath_with_static_members(_ p: P_With_Static_Members) {
754
777
755
778
func foo( _ s: S ) {
756
779
let _ = \S . Type. foo
757
- // expected-error@-1 {{key path cannot refer to static member 'foo'}}
758
780
let _ = s [ keyPath: \. foo]
759
- // expected-error@-1 {{key path cannot refer to static member 'foo '}}
781
+ // expected-error@-1 {{static member 'foo' cannot be used on instance of type 'S '}}
760
782
let _: KeyPath < S , String > = \. foo
761
- // expected-error@-1 {{key path cannot refer to static member 'foo '}}
783
+ // expected-error@-1 {{static member 'foo' cannot be used on instance of type 'S '}}
762
784
let _ = \S . foo
763
- // expected-error@-1 {{key path cannot refer to static member 'foo '}}
785
+ // expected-error@-1 {{static member 'foo' cannot be used on instance of type 'S '}}
764
786
let _ = \S . bar. baz
765
- // expected-error@-1 {{key path cannot refer to static member 'baz '}}
787
+ // expected-error@-1 {{static member 'baz' cannot be used on instance of type 'Bar '}}
766
788
let _ = s [ keyPath: \. bar. baz]
767
- // expected-error@-1 {{key path cannot refer to static member 'baz '}}
789
+ // expected-error@-1 {{static member 'baz' cannot be used on instance of type 'Bar '}}
768
790
}
769
791
}
770
792
0 commit comments