mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Test] Add AnyKeyPath test and move keypath diagnostics
This commit is contained in:
@@ -1565,18 +1565,18 @@ func testNilCoalescingOperatorRemoveFix() {
|
||||
let _ = "" /* This is a comment */ ?? "" // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{13-43=}}
|
||||
|
||||
let _ = "" // This is a comment
|
||||
?? "" // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{1567:13-1568:10=}}
|
||||
?? "" // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{1555:13-1556:10=}}
|
||||
|
||||
let _ = "" // This is a comment
|
||||
/*
|
||||
* The blank line below is part of the test case, do not delete it
|
||||
*/
|
||||
|
||||
?? "" // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{1570:13-1575:10=}}
|
||||
?? "" // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{1558:13-1563:10=}}
|
||||
|
||||
if ("" ?? // This is a comment // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{1577:9-1578:9=}}
|
||||
if ("" ?? // This is a comment // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{9-1566:9=}}
|
||||
"").isEmpty {}
|
||||
|
||||
if ("" // This is a comment
|
||||
?? "").isEmpty {} // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{1580:9-1581:12=}}
|
||||
?? "").isEmpty {} // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{1568:9-1569:12=}}
|
||||
}
|
||||
|
||||
@@ -236,3 +236,14 @@ func issue_65965() {
|
||||
writeKP = \.v
|
||||
// expected-error@-1 {{key path value type 'KeyPath<S, String>' cannot be converted to contextual type 'WritableKeyPath<S, String>'}}
|
||||
}
|
||||
|
||||
func test_any_key_path() {
|
||||
struct S {
|
||||
var v: String
|
||||
}
|
||||
|
||||
var anyKP: AnyKeyPath
|
||||
anyKP = \S.v
|
||||
anyKP = \.v
|
||||
// expected-error@-1 {{cannot infer key path type from context; consider explicitly specifying a root type}}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user