Skip to content

Commit aa5ddfd

Browse files
author
Greg Titus
committed
Fix hole where missing_nullary_call wasn't diagnosed in ternary condition.
1 parent 25830d6 commit aa5ddfd

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3168,6 +3168,14 @@ bool ContextualFailure::diagnoseConversionToBool() const {
31683168
return true;
31693169
}
31703170

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+
31713179
return false;
31723180
}
31733181

test/Constraints/ternary_expr.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ _ = true ? x : 1.2 // expected-error {{result values in '? :' expression have mi
5959
_ = (x: true) ? true : false // expected-error {{cannot convert value of type '(x: Bool)' to expected condition type 'Bool'}}
6060
_ = (x: 1) ? true : false // expected-error {{cannot convert value of type '(x: Int)' to expected condition type 'Bool'}}
6161

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+
6265
let ib: Bool! = false
6366
let eb: Bool? = .some(false)
6467
let conditional = ib ? "Broken" : "Heart" // should infer Bool!

0 commit comments

Comments
 (0)