You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/expr/unary/keypath/keypath.swift
+29
Original file line number
Diff line number
Diff line change
@@ -895,11 +895,40 @@ struct SR_12290 {
895
895
896
896
func testKeyPathHole(){
897
897
_ = \.x // expected-error {{cannot infer key path type from context; consider explicitly specifying a root type}} {{8-8=<#Root#>}}
898
+
_ = \.x.y // expected-error {{cannot infer key path type from context; consider explicitly specifying a root type}} {{8-8=<#Root#>}}
899
+
898
900
let _ :AnyKeyPath= \.x
899
901
// expected-error@-1 {{'AnyKeyPath' does not provide enough context for root type to be inferred; consider explicitly specifying a root type}} {{25-25=<#Root#>}}
902
+
let _ :AnyKeyPath= \.x.y
903
+
// expected-error@-1 {{'AnyKeyPath' does not provide enough context for root type to be inferred; consider explicitly specifying a root type}} {{25-25=<#Root#>}}
900
904
901
905
func f(_ i:Int){}
902
906
f(\.x) // expected-error {{cannot infer key path type from context; consider explicitly specifying a root type}} {{6-6=<#Root#>}}
907
+
f(\.x.y) // expected-error {{cannot infer key path type from context; consider explicitly specifying a root type}} {{6-6=<#Root#>}}
908
+
909
+
// FIXME(SR-12827): Instead of "generic parameter 'T' could not be inferred",
910
+
// we should offer the same diagnostic as above.
911
+
func provideValueButNotRoot<T>(_ fn:(T)->String){} // expected-note 2{{in call to function 'provideValueButNotRoot'}}
912
+
provideValueButNotRoot(\.x) // expected-error {{generic parameter 'T' could not be inferred}}
913
+
provideValueButNotRoot(\.x.y) // expected-error {{generic parameter 'T' could not be inferred}}
914
+
provideValueButNotRoot(\String.foo) // expected-error {{value of type 'String' has no member 'foo'}}
915
+
916
+
func provideKPValueButNotRoot<T>(_ kp:KeyPath<T,String>){} // expected-note 3{{in call to function 'provideKPValueButNotRoot'}}
917
+
provideKPValueButNotRoot(\.x) // expected-error {{generic parameter 'T' could not be inferred}}
918
+
provideKPValueButNotRoot(\.x.y) // expected-error {{generic parameter 'T' could not be inferred}}
919
+
provideKPValueButNotRoot(\String.foo)
920
+
// expected-error@-1 {{value of type 'String' has no member 'foo'}}
921
+
// expected-error@-2 {{generic parameter 'T' could not be inferred}}
922
+
}
923
+
924
+
func testMissingMember(){
925
+
let _:KeyPath<String,String>= \.foo // expected-error {{value of type 'String' has no member 'foo'}}
926
+
let _:KeyPath<String,String>= \.foo.bar // expected-error {{value of type 'String' has no member 'foo'}}
927
+
928
+
let _:PartialKeyPath<String>= \.foo // expected-error {{value of type 'String' has no member 'foo'}}
929
+
let _:PartialKeyPath<String>= \.foo.bar // expected-error {{value of type 'String' has no member 'foo'}}
930
+
931
+
_ = \String.x.y // expected-error {{value of type 'String' has no member 'x'}}
0 commit comments