mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Tests] Add and update tests
This commit is contained in:
@@ -136,8 +136,8 @@ func test_mismatch_with_contextual_optional_result() {
|
||||
var arr: [Int] = []
|
||||
}
|
||||
|
||||
let _ = A(B(), keyPath: \.arr)
|
||||
// expected-error@-1 {{key path value type '[Int]' cannot be converted to contextual type '[Int]?'}}
|
||||
let _ = A(B(), keyPath: \.arr) // expected-error {{cannot convert value of type 'KeyPath<B, [Int]>' to expected argument type 'KeyPath<B, [Int]?>'}}
|
||||
// expected-note@-1 {{arguments to generic parameter 'Value' ('[Int]' and '[Int]?') are expected to be equal}}
|
||||
}
|
||||
|
||||
// https://github.com/apple/swift/issues/53581
|
||||
@@ -180,6 +180,20 @@ func key_path_root_mismatch<T>(_ base: KeyPathBase?, subBase: KeyPathBaseSubtype
|
||||
|
||||
}
|
||||
|
||||
func key_path_value_mismatch() {
|
||||
struct S {
|
||||
var member: Int
|
||||
}
|
||||
|
||||
func test(_: KeyPath<S, String>) {}
|
||||
// expected-note@-1 {{found candidate with type 'KeyPath<S, Int>'}}
|
||||
func test(_: KeyPath<S, Float>) {}
|
||||
// expected-note@-1 {{found candidate with type 'KeyPath<S, Int>'}}
|
||||
|
||||
test(\.member)
|
||||
// expected-error@-1 {{no exact matches in call to local function 'test'}}
|
||||
}
|
||||
|
||||
// https://github.com/apple/swift/issues/55884
|
||||
func f_55884() {
|
||||
func f<T>(_ x: KeyPath<String?, T>) -> T { "1"[keyPath: x] }
|
||||
|
||||
@@ -28,4 +28,5 @@ struct S4 {
|
||||
subscript(v: KeyPath<S4, String>) -> Int { get { 0 } set(newValue) {} }
|
||||
}
|
||||
var s4 = S4()
|
||||
s4[\.x] = 10 // expected-error {{key path value type 'Int' cannot be converted to contextual type 'String'}}
|
||||
s4[\.x] = 10 // expected-error {{cannot convert value of type 'KeyPath<S4, Int>' to expected argument type 'KeyPath<S4, String>'}}
|
||||
// expected-note@-1 {{arguments to generic parameter 'Value' ('Int' and 'String') are expected to be equal}}
|
||||
|
||||
@@ -228,7 +228,7 @@ func testNoComponents() {
|
||||
let _: KeyPath<A, A> = \A // expected-error{{must have at least one component}}
|
||||
let _: KeyPath<C, A> = \C // expected-error{{must have at least one component}}
|
||||
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
|
||||
let _: KeyPath<A, C> = \A // expected-error{{must have at least one component}}
|
||||
let _: KeyPath<A, C> = \A // expected-error{{must have at least one component}}
|
||||
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
|
||||
_ = \A // expected-error {{key path must have at least one component}}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user