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
We currently leave a key path constraint unsolved
if one of its components hasn't yet had its
overload resolved. However, for e.g a missing
member component, the overload type variable will
be bound to a hole and an overload will never be
resolved.
Tweak the logic to consider the key path constraint
trivially solved if one of its components has been
marked as a hole, which will allow the key path
type itself to be marked as a hole.
Resolves SR-12437 & SR-12823.
Resolves rdar://62201037.
Copy file name to clipboardExpand all lines: test/expr/unary/keypath/keypath.swift
+29Lines changed: 29 additions & 0 deletions
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