Skip to content

Commit b8cba10

Browse files
committed
[CSApply] Use fully qualified locator while coercing ternary branches
The locator needs to much what was produced by constraint generator otherwise Double<->CGFloat implicit coercion wouldn't be able to find the overload choice.
1 parent 7cc6892 commit b8cba10

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lib/Sema/CSApply.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3735,10 +3735,12 @@ namespace {
37353735
expr->setCondExpr(cond);
37363736

37373737
// Coerce the then/else branches to the common type.
3738-
expr->setThenExpr(coerceToType(expr->getThenExpr(), resultTy,
3739-
cs.getConstraintLocator(expr->getThenExpr())));
3740-
expr->setElseExpr(coerceToType(expr->getElseExpr(), resultTy,
3741-
cs.getConstraintLocator(expr->getElseExpr())));
3738+
expr->setThenExpr(coerceToType(
3739+
expr->getThenExpr(), resultTy,
3740+
cs.getConstraintLocator(expr, LocatorPathElt::TernaryBranch(true))));
3741+
expr->setElseExpr(coerceToType(
3742+
expr->getElseExpr(), resultTy,
3743+
cs.getConstraintLocator(expr, LocatorPathElt::TernaryBranch(false))));
37423744

37433745
return expr;
37443746
}

test/Constraints/implicit_double_cgfloat_conversion.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,12 @@ func assignments_with_and_without_optionals() {
253253
var prop: CGFloat = 0
254254
}
255255

256-
func test(c: C?, v: Double) {
256+
func test(c: C?, v: Double, cgf: CGFloat) {
257257
c?.prop = v / 2.0 // Ok
258+
c?.prop = (false ? cgf : v)
258259

259260
let copy = c!
260261
copy.prop = Optional(v) ?? 0 // Ok
262+
copy.prop = (true ? cgf : (false ? v : cgf))
261263
}
262264
}

0 commit comments

Comments
 (0)