Skip to content

Commit fef908e

Browse files
[Sema] Increase impact of ternary then branch aiming better diagnostics
1 parent c3fbe24 commit fef908e

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
@@ -14753,8 +14753,15 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1475314753
// means that result would attempt a type from each side if
1475414754
// one is available and that would result in two fixes - one for
1475514755
// each mismatched branch.
14756-
if (branchElt->forElse())
14756+
if (branchElt->forElse()) {
1475714757
impact = 10;
14758+
} else {
14759+
// Also increase impact for `then` branch lower than `else` to still
14760+
// eliminate ambiguity, but slightly worst than the average fix to avoid
14761+
// so the solution which record this fix wouldn't be picked over one
14762+
// that has contextual mismatch fix on the result of ternary expression.
14763+
impact = 5;
14764+
}
1475814765
}
1475914766
using SingleValueStmtBranch = LocatorPathElt::SingleValueStmtBranch;
1476014767
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)