Skip to content

Commit 51a0296

Browse files
committed
[Diagnostics] NFC: Adjust all of the improved if/ternary test-cases
1 parent c4fee1d commit 51a0296

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

test/Constraints/diagnostics.swift

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,22 +1260,15 @@ func rdar17170728() {
12601260
var j: Int?
12611261
var k: Int? = 2
12621262

1263-
let _ = [i, j, k].reduce(0 as Int?) { // expected-error 3 {{cannot convert value of type 'Int?' to expected element type 'Bool'}}
1264-
// expected-error@-1 {{optional type 'Int?' cannot be used as a boolean; test for '!= nil' instead}}
1263+
let _ = [i, j, k].reduce(0 as Int?) {
12651264
$0 && $1 ? $0! + $1! : ($0 ? $0! : ($1 ? $1! : nil))
1266-
// expected-error@-1 {{binary operator '+' cannot be applied to two 'Bool' operands}}
1267-
// expected-error@-2 4 {{cannot force unwrap value of non-optional type 'Bool'}}
1268-
// expected-error@-3 {{value of optional type 'Bool?' must be unwrapped to a value of type 'Bool'}}
1269-
// expected-note@-4 {{coalesce using '??' to provide a default when the optional value contains 'nil'}}
1270-
// expected-note@-5 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}}
1265+
// expected-error@-1 4 {{optional type 'Int?' cannot be used as a boolean; test for '!= nil' instead}}
12711266
}
12721267

1273-
let _ = [i, j, k].reduce(0 as Int?) { // expected-error 3 {{cannot convert value of type 'Int?' to expected element type 'Bool'}}
1274-
// expected-error@-1 {{missing argument label 'into:' in call}}
1275-
// expected-error@-2 {{optional type 'Int?' cannot be used as a boolean; test for '!= nil' instead}}
1268+
let _ = [i, j, k].reduce(0 as Int?) {
12761269
$0 && $1 ? $0 + $1 : ($0 ? $0 : ($1 ? $1 : nil))
1277-
// expected-error@-1 {{binary operator '+' cannot be applied to two 'Bool' operands}}
1278-
// expected-error@-2 {{'nil' cannot be used in context expecting type 'Bool'}}
1270+
// expected-error@-1 {{binary operator '+' cannot be applied to two 'Int?' operands}}
1271+
// expected-error@-2 4 {{optional type 'Int?' cannot be used as a boolean; test for '!= nil' instead}}
12791272
}
12801273
}
12811274

test/Constraints/if_expr.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ useDouble(c)
2828
useDouble(d)
2929

3030
var z = true ? a : b // expected-error{{result values in '? :' expression have mismatching types 'Int' and 'Double'}}
31-
var _ = a ? b : b // expected-error{{'Int' is not convertible to 'Bool'}}
31+
var _ = a ? b : b // expected-error{{cannot convert value of type 'Int' to expected condition type 'Bool'}}
3232

3333

3434

@@ -51,13 +51,13 @@ useD1(i) // expected-error{{cannot convert value of type 'B' to expected argumen
5151
useD2(i) // expected-error{{cannot convert value of type 'B' to expected argument type 'D2'}}
5252

5353
var x = true ? 1 : 0
54-
var y = 22 ? 1 : 0 // expected-error{{'Int' is not convertible to 'Bool'}}
54+
var y = 22 ? 1 : 0 // expected-error{{cannot convert value of type 'Int' to expected condition type 'Bool'}}
5555

56-
_ = x ? x : x // expected-error {{'Int' is not convertible to 'Bool'}}
56+
_ = x ? x : x // expected-error {{cannot convert value of type 'Int' to expected condition type 'Bool'}}
5757
_ = true ? x : 1.2 // expected-error {{result values in '? :' expression have mismatching types 'Int' and 'Double'}}
5858

59-
_ = (x: true) ? true : false // expected-error {{'(x: Bool)' is not convertible to 'Bool'}}
60-
_ = (x: 1) ? true : false // expected-error {{'(x: Int)' is not convertible to 'Bool'}}
59+
_ = (x: true) ? true : false // expected-error {{cannot convert value of type '(x: Bool)' to expected condition type 'Bool'}}
60+
_ = (x: 1) ? true : false // expected-error {{cannot convert value of type '(x: Int)' to expected condition type 'Bool'}}
6161

6262
let ib: Bool! = false
6363
let eb: Bool? = .some(false)

test/Sema/diag_erroneous_iuo.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,6 @@ struct T {
219219
}
220220

221221
func select(i: Int!, m: Int, t: T) {
222-
let _ = i ? i : m // expected-error {{result values in '? :' expression have mismatching types 'Int?' and 'Int'}}
223-
let _ = t.i ? t.j : t.k // expected-error {{result values in '? :' expression have mismatching types 'Int?' and 'Int'}}
222+
let _ = i ? i : m // expected-error {{optional type 'Int?' cannot be used as a boolean; test for '!= nil' instead}} {{11-11=(}} {{12-12= != nil)}}
223+
let _ = t.i ? t.j : t.k // expected-error {{optional type 'Int?' cannot be used as a boolean; test for '!= nil' instead}} {{11-11=(}} {{14-14= != nil)}}
224224
}

0 commit comments

Comments
 (0)