Skip to content

Commit 1d90de1

Browse files
Merge pull request #66208 from LucianoPAlmeida/diag-ternary
[Sema] Increase impact of ternary then branch aiming better diagnostics
2 parents 5db2b28 + fef908e commit 1d90de1

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14778,8 +14778,15 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1477814778
// means that result would attempt a type from each side if
1477914779
// one is available and that would result in two fixes - one for
1478014780
// each mismatched branch.
14781-
if (branchElt->forElse())
14781+
if (branchElt->forElse()) {
1478214782
impact = 10;
14783+
} else {
14784+
// Also increase impact for `then` branch lower than `else` to still
14785+
// eliminate ambiguity, but slightly worst than the average fix to avoid
14786+
// so the solution which record this fix wouldn't be picked over one
14787+
// that has contextual mismatch fix on the result of ternary expression.
14788+
impact = 5;
14789+
}
1478314790
}
1478414791
using SingleValueStmtBranch = LocatorPathElt::SingleValueStmtBranch;
1478514792
if (auto branchElt = locator->getLastElementAs<SingleValueStmtBranch>()) {

test/expr/expressions.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,3 +951,7 @@ let _ = "foo \(42 /*
951951
// expected-error @-3 {{cannot find ')' to match opening '(' in string interpolation}} expected-error @-3 {{unterminated string literal}}
952952
// expected-error @-2 {{expected expression}}
953953
// expected-error @-3 {{unterminated string literal}}
954+
955+
// https://github.com/apple/swift/issues/66192
956+
func I66192(_: Int) {}
957+
I66192(true ? "yes" : "no") // expected-error{{cannot convert value of type 'String' to expected argument type 'Int'}}

0 commit comments

Comments
 (0)