@@ -3541,9 +3541,11 @@ namespace {
3541
3541
3542
3542
auto elementType = expr->getElementType ();
3543
3543
3544
- for (auto &element : expr->getElements ()) {
3545
- element = coerceToType (element, elementType,
3546
- cs.getConstraintLocator (element));
3544
+ for (unsigned i = 0 , n = expr->getNumElements (); i != n; ++i) {
3545
+ expr->setElement (
3546
+ i, coerceToType (expr->getElement (i), elementType,
3547
+ cs.getConstraintLocator (
3548
+ expr, {LocatorPathElt::TupleElement (i)})));
3547
3549
}
3548
3550
3549
3551
return expr;
@@ -3586,9 +3588,12 @@ namespace {
3586
3588
expr->setInitializer (witness);
3587
3589
3588
3590
auto elementType = expr->getElementType ();
3589
- for (auto &element : expr->getElements ()) {
3590
- element = coerceToType (element, elementType,
3591
- cs.getConstraintLocator (element));
3591
+
3592
+ for (unsigned i = 0 , n = expr->getNumElements (); i != n; ++i) {
3593
+ expr->setElement (
3594
+ i, coerceToType (expr->getElement (i), elementType,
3595
+ cs.getConstraintLocator (
3596
+ expr, {LocatorPathElt::TupleElement (i)})));
3592
3597
}
3593
3598
3594
3599
return expr;
@@ -3790,10 +3795,12 @@ namespace {
3790
3795
expr->setCondExpr (cond);
3791
3796
3792
3797
// Coerce the then/else branches to the common type.
3793
- expr->setThenExpr (coerceToType (expr->getThenExpr (), resultTy,
3794
- cs.getConstraintLocator (expr->getThenExpr ())));
3795
- expr->setElseExpr (coerceToType (expr->getElseExpr (), resultTy,
3796
- cs.getConstraintLocator (expr->getElseExpr ())));
3798
+ expr->setThenExpr (coerceToType (
3799
+ expr->getThenExpr (), resultTy,
3800
+ cs.getConstraintLocator (expr, LocatorPathElt::TernaryBranch (true ))));
3801
+ expr->setElseExpr (coerceToType (
3802
+ expr->getElseExpr (), resultTy,
3803
+ cs.getConstraintLocator (expr, LocatorPathElt::TernaryBranch (false ))));
3797
3804
3798
3805
return expr;
3799
3806
}
@@ -4365,9 +4372,12 @@ namespace {
4365
4372
Expr *visitAssignExpr (AssignExpr *expr) {
4366
4373
// Convert the source to the simplified destination type.
4367
4374
auto destTy = simplifyType (cs.getType (expr->getDest ()));
4368
- auto locator =
4369
- ConstraintLocatorBuilder (cs.getConstraintLocator (expr->getSrc ()));
4370
- Expr *src = coerceToType (expr->getSrc (), destTy->getRValueType (), locator);
4375
+ // Conversion is recorded as anchored on an assignment itself by
4376
+ // constraint generator and that has to be preserved here in case
4377
+ // anything depends on the locator (i.e. Double<->CGFloat implicit
4378
+ // conversion).
4379
+ Expr *src = coerceToType (expr->getSrc (), destTy->getRValueType (),
4380
+ cs.getConstraintLocator (expr));
4371
4381
if (!src)
4372
4382
return nullptr ;
4373
4383
@@ -6821,6 +6831,11 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
6821
6831
auto *argExpr = locator.trySimplifyToExpr ();
6822
6832
assert (argExpr);
6823
6833
6834
+ // Source requires implicit conversion to match destination
6835
+ // type but the conversion itself is recorded on assignment.
6836
+ if (auto *assignment = dyn_cast<AssignExpr>(argExpr))
6837
+ argExpr = assignment->getSrc ();
6838
+
6824
6839
// Load the value for conversion.
6825
6840
argExpr = cs.coerceToRValue (argExpr);
6826
6841
0 commit comments