@@ -1183,23 +1183,30 @@ func sr5081() {
1183
1183
b = a [ 2 ... 4 ] // expected-error {{cannot assign value of type 'ArraySlice<String>' to type '[String]'}}
1184
1184
}
1185
1185
1186
- /**
1187
- * TODO(diagnostics):Figure out what to do when expressions are complex and completely broken
1188
- *
1186
+ // TODO(diagnostics):Figure out what to do when expressions are complex and completely broken
1189
1187
func rdar17170728( ) {
1190
1188
var i : Int ? = 1
1191
1189
var j : Int ?
1192
1190
var k : Int ? = 2
1193
1191
1194
- let _ = [i, j, k].reduce(0 as Int?) {
1192
+ let _ = [ i, j, k] . reduce ( 0 as Int ? ) { // expected-error 3 {{cannot convert value of type 'Int?' to expected element type 'Bool'}}
1193
+ // expected-error@-1 {{optional type 'Int?' cannot be used as a boolean; test for '!= nil' instead}}
1195
1194
$0 && $1 ? $0! + $1! : ( $0 ? $0! : ( $1 ? $1! : nil ) )
1195
+ // expected-error@-1 {{binary operator '+' cannot be applied to two 'Bool' operands}}
1196
+ // expected-error@-2 4 {{cannot force unwrap value of non-optional type 'Bool'}}
1197
+ // expected-error@-3 {{value of optional type 'Bool?' must be unwrapped to a value of type 'Bool'}}
1198
+ // expected-note@-4 {{coalesce using '??' to provide a default when the optional value contains 'nil'}}
1199
+ // expected-note@-5 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}}
1196
1200
}
1197
1201
1198
- let _ = [i, j, k].reduce(0 as Int?) {
1202
+ let _ = [ i, j, k] . reduce ( 0 as Int ? ) { // expected-error 3 {{cannot convert value of type 'Int?' to expected element type 'Bool'}}
1203
+ // expected-error@-1 {{missing argument label 'into:' in call}}
1204
+ // expected-error@-2 {{optional type 'Int?' cannot be used as a boolean; test for '!= nil' instead}}
1199
1205
$0 && $1 ? $0 + $1 : ( $0 ? $0 : ( $1 ? $1 : nil ) )
1206
+ // expected-error@-1 {{binary operator '+' cannot be applied to operands of type '@lvalue Bool' and 'Bool'}}
1207
+ // expected-error@-2 {{'nil' cannot be used in context expecting type 'Bool'}}
1200
1208
}
1201
1209
}
1202
- */
1203
1210
1204
1211
// https://bugs.swift.org/browse/SR-5934 - failure to emit diagnostic for bad
1205
1212
// generic constraints
0 commit comments