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
let _:AnyKeyPath= \.property // expected-error{{ambiguous}}
198
+
let _:AnyKeyPath= \.property // expected-error {{'AnyKeyPath' does not provide enough context for root type to be inferred; consider explicitly specifying a root type}} {{24-24=<#Root#>}}
199
199
let _:AnyKeyPath= \C.value // expected-error{{generic parameter 'T' could not be inferred}}
200
-
let _:AnyKeyPath= \.value // expected-error{{ambiguous}}
200
+
let _:AnyKeyPath= \.value // expected-error {{'AnyKeyPath' does not provide enough context for root type to be inferred; consider explicitly specifying a root type}} {{24-24=<#Root#>}}
201
201
202
202
let _ = \Prop.[nonHashableSub] // expected-error{{subscript index of type 'NonHashableSub' in a key path must be Hashable}}
203
203
let _ = \Prop.[sub, sub]
@@ -893,6 +893,44 @@ struct SR_12290 {
893
893
}
894
894
}
895
895
896
+
func testKeyPathHole(){
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
+
900
+
let _ :AnyKeyPath= \.x
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#>}}
904
+
905
+
func f(_ i:Int){}
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'}}
932
+
}
933
+
896
934
func testSyntaxErrors(){ // expected-note{{}}
897
935
_ = \. ; // expected-error{{expected member name following '.'}}
0 commit comments