Skip to content

Commit 59d2679

Browse files
author
Amritpan Kaur
committed
[Test] Add AnyKeyPath test and move keypath diagnostics
1 parent 3604551 commit 59d2679

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

test/Constraints/diagnostics.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,18 +1565,18 @@ func testNilCoalescingOperatorRemoveFix() {
15651565
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=}}
15661566

15671567
let _ = "" // This is a comment
1568-
?? "" // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{1567:13-1568:10=}}
1568+
?? "" // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{1555:13-1556:10=}}
15691569

15701570
let _ = "" // This is a comment
15711571
/*
15721572
* The blank line below is part of the test case, do not delete it
15731573
*/
15741574

1575-
?? "" // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{1570:13-1575:10=}}
1575+
?? "" // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{1558:13-1563:10=}}
15761576

1577-
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=}}
1577+
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=}}
15781578
"").isEmpty {}
15791579

15801580
if ("" // This is a comment
1581-
?? "").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=}}
1581+
?? "").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=}}
15821582
}

test/Constraints/keypath.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,14 @@ func issue_65965() {
236236
writeKP = \.v
237237
// expected-error@-1 {{key path value type 'KeyPath<S, String>' cannot be converted to contextual type 'WritableKeyPath<S, String>'}}
238238
}
239+
240+
func test_any_key_path() {
241+
struct S {
242+
var v: String
243+
}
244+
245+
var anyKP: AnyKeyPath
246+
anyKP = \S.v
247+
anyKP = \.v
248+
// expected-error@-1 {{cannot infer key path type from context; consider explicitly specifying a root type}}
249+
}

0 commit comments

Comments
 (0)