@@ -524,16 +524,39 @@ func testInvalidKeyPathComponents() {
524524 let _ = \. { return 0 } // expected-error* {{}}
525525}
526526
527+ struct W {
528+ static let h = 50
529+ }
530+
527531class X {
528532 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 }
530542}
531543
532544func 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 ]
537560}
538561
539562class Bass : Hashable {
@@ -735,13 +758,13 @@ protocol P_With_Static_Members {
735758
736759func test_keypath_with_static_members( _ p: P_With_Static_Members ) {
737760 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 '}}
739762 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 '}}
741764 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 '}}
743766 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 '}}
745768
746769 struct S {
747770 static var foo : String = " Hello "
@@ -754,17 +777,16 @@ func test_keypath_with_static_members(_ p: P_With_Static_Members) {
754777
755778 func foo( _ s: S ) {
756779 let _ = \S . Type. foo
757- // expected-error@-1 {{key path cannot refer to static member 'foo'}}
758780 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 '}}
760782 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 '}}
762784 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 '}}
764786 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 '}}
766788 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 '}}
768790 }
769791}
770792
0 commit comments