mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CS] Don't leave key path with holes unsolved
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.
This commit is contained in:
@@ -895,11 +895,40 @@ struct SR_12290 {
|
||||
|
||||
func testKeyPathHole() {
|
||||
_ = \.x // expected-error {{cannot infer key path type from context; consider explicitly specifying a root type}} {{8-8=<#Root#>}}
|
||||
_ = \.x.y // expected-error {{cannot infer key path type from context; consider explicitly specifying a root type}} {{8-8=<#Root#>}}
|
||||
|
||||
let _ : AnyKeyPath = \.x
|
||||
// expected-error@-1 {{'AnyKeyPath' does not provide enough context for root type to be inferred; consider explicitly specifying a root type}} {{25-25=<#Root#>}}
|
||||
let _ : AnyKeyPath = \.x.y
|
||||
// expected-error@-1 {{'AnyKeyPath' does not provide enough context for root type to be inferred; consider explicitly specifying a root type}} {{25-25=<#Root#>}}
|
||||
|
||||
func f(_ i: Int) {}
|
||||
f(\.x) // expected-error {{cannot infer key path type from context; consider explicitly specifying a root type}} {{6-6=<#Root#>}}
|
||||
f(\.x.y) // expected-error {{cannot infer key path type from context; consider explicitly specifying a root type}} {{6-6=<#Root#>}}
|
||||
|
||||
// FIXME(SR-12827): Instead of "generic parameter 'T' could not be inferred",
|
||||
// we should offer the same diagnostic as above.
|
||||
func provideValueButNotRoot<T>(_ fn: (T) -> String) {} // expected-note 2{{in call to function 'provideValueButNotRoot'}}
|
||||
provideValueButNotRoot(\.x) // expected-error {{generic parameter 'T' could not be inferred}}
|
||||
provideValueButNotRoot(\.x.y) // expected-error {{generic parameter 'T' could not be inferred}}
|
||||
provideValueButNotRoot(\String.foo) // expected-error {{value of type 'String' has no member 'foo'}}
|
||||
|
||||
func provideKPValueButNotRoot<T>(_ kp: KeyPath<T, String>) {} // expected-note 3{{in call to function 'provideKPValueButNotRoot'}}
|
||||
provideKPValueButNotRoot(\.x) // expected-error {{generic parameter 'T' could not be inferred}}
|
||||
provideKPValueButNotRoot(\.x.y) // expected-error {{generic parameter 'T' could not be inferred}}
|
||||
provideKPValueButNotRoot(\String.foo)
|
||||
// expected-error@-1 {{value of type 'String' has no member 'foo'}}
|
||||
// expected-error@-2 {{generic parameter 'T' could not be inferred}}
|
||||
}
|
||||
|
||||
func testMissingMember() {
|
||||
let _: KeyPath<String, String> = \.foo // expected-error {{value of type 'String' has no member 'foo'}}
|
||||
let _: KeyPath<String, String> = \.foo.bar // expected-error {{value of type 'String' has no member 'foo'}}
|
||||
|
||||
let _: PartialKeyPath<String> = \.foo // expected-error {{value of type 'String' has no member 'foo'}}
|
||||
let _: PartialKeyPath<String> = \.foo.bar // expected-error {{value of type 'String' has no member 'foo'}}
|
||||
|
||||
_ = \String.x.y // expected-error {{value of type 'String' has no member 'x'}}
|
||||
}
|
||||
|
||||
func testSyntaxErrors() { // expected-note{{}}
|
||||
|
||||
Reference in New Issue
Block a user