File tree Expand file tree Collapse file tree 2 files changed +11
-0
lines changed Expand file tree Collapse file tree 2 files changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -3168,6 +3168,14 @@ bool ContextualFailure::diagnoseConversionToBool() const {
3168
3168
return true ;
3169
3169
}
3170
3170
3171
+ if (auto fnType = getFromType ()->getAs <FunctionType>()) {
3172
+ if (fnType->getResult ()->isBool () && fnType->getNumParams () == 0 ) {
3173
+ emitDiagnostic (diag::missing_nullary_call, toType)
3174
+ .fixItInsertAfter (getSourceRange ().End , " ()" );
3175
+ return true ;
3176
+ }
3177
+ }
3178
+
3171
3179
return false ;
3172
3180
}
3173
3181
Original file line number Diff line number Diff line change @@ -59,6 +59,9 @@ _ = true ? x : 1.2 // expected-error {{result values in '? :' expression have mi
59
59
_ = ( x: true ) ? true : false // expected-error {{cannot convert value of type '(x: Bool)' to expected condition type 'Bool'}}
60
60
_ = ( x: 1 ) ? true : false // expected-error {{cannot convert value of type '(x: Int)' to expected condition type 'Bool'}}
61
61
62
+ func resultBool( ) -> Bool { true }
63
+ _ = resultBool ? true : false // expected-error {{function produces expected type 'Bool'; did you mean to call it with '()'?}} {{15-15=()}}
64
+
62
65
let ib : Bool ! = false
63
66
let eb : Bool ? = . some( false )
64
67
let conditional = ib ? " Broken " : " Heart " // should infer Bool!
You can’t perform that action at this time.
0 commit comments