File tree Expand file tree Collapse file tree 4 files changed +22
-19
lines changed Expand file tree Collapse file tree 4 files changed +22
-19
lines changed Original file line number Diff line number Diff line change @@ -3525,12 +3525,20 @@ namespace {
3525
3525
// Turn the subexpression into an rvalue.
3526
3526
auto rvalueSub = cs.coerceToRValue (expr->getSubExpr ());
3527
3527
expr->setSubExpr (rvalueSub);
3528
-
3528
+
3529
+ auto *locator = [&]() {
3530
+ // Only adding this path for explicty coercions e.g _ = a as Int
3531
+ // and for non literal/array-literal subExpr.
3532
+ if (!expr->isImplicit ()
3533
+ && !isa<LiteralExpr>(expr->getSubExpr ())
3534
+ && !isa<CollectionExpr>(expr->getSubExpr ()))
3535
+ return cs.getConstraintLocator (expr, LocatorPathElt::ExplicitTypeCoercion ());
3536
+ return cs.getConstraintLocator (expr);
3537
+ }();
3538
+
3529
3539
// If we weren't explicitly told by the caller which disjunction choice,
3530
3540
// get it from the solution to determine whether we've picked a coercion
3531
3541
// or a bridging conversion.
3532
- auto *locator = cs.getConstraintLocator (expr);
3533
-
3534
3542
if (!choice) {
3535
3543
choice = solution.getDisjunctionChoice (locator);
3536
3544
}
Original file line number Diff line number Diff line change @@ -2661,7 +2661,15 @@ namespace {
2661
2661
CS.setType (expr->getCastTypeLoc (), toType);
2662
2662
2663
2663
auto fromType = CS.getType (expr->getSubExpr ());
2664
- auto locator = CS.getConstraintLocator (expr);
2664
+ auto locator = [&]() {
2665
+ // Only adding this path for explicty coercions e.g _ = a as Int
2666
+ // and for non literal/array-literal subExpr.
2667
+ if (!expr->isImplicit ()
2668
+ && !isa<LiteralExpr>(expr->getSubExpr ())
2669
+ && !isa<CollectionExpr>(expr->getSubExpr ()))
2670
+ return CS.getConstraintLocator (expr, LocatorPathElt::ExplicitTypeCoercion ());
2671
+ return CS.getConstraintLocator (expr);
2672
+ }();
2665
2673
2666
2674
// Add a conversion constraint for the direct conversion between
2667
2675
// types.
@@ -2672,7 +2680,7 @@ namespace {
2672
2680
// bindings for the result of the coercion.
2673
2681
auto *TR = expr->getCastTypeLoc ().getTypeRepr ();
2674
2682
if (TR && TR->getKind () == TypeReprKind::ImplicitlyUnwrappedOptional)
2675
- return createTypeVariableAndDisjunctionForIUOCoercion (toType, locator );
2683
+ return createTypeVariableAndDisjunctionForIUOCoercion (toType, CS. getConstraintLocator (expr) );
2676
2684
2677
2685
return toType;
2678
2686
}
Original file line number Diff line number Diff line change @@ -7754,21 +7754,9 @@ void ConstraintSystem::addExplicitConversionConstraint(
7754
7754
auto locatorPtr = getConstraintLocator (locator);
7755
7755
7756
7756
// Coercion (the common case).
7757
- auto coerceLocator = [&]() {
7758
- if (auto expr = dyn_cast_or_null<CoerceExpr>(locatorPtr->getAnchor ())) {
7759
- // Only adding this path for explicty coercions e.g _ = a as Int
7760
- // and for non lireal subExpr.
7761
- if (!expr->isImplicit ()
7762
- && !isa<LiteralExpr>(expr->getSubExpr ())
7763
- && !isa<CollectionExpr>(expr->getSubExpr ()))
7764
- return getConstraintLocator (locator.getBaseLocator (), LocatorPathElt::ExplicitTypeCoercion ());
7765
- }
7766
- return locatorPtr;
7767
- }();
7768
-
7769
7757
Constraint *coerceConstraint =
7770
7758
Constraint::create (*this , ConstraintKind::Conversion,
7771
- fromType, toType, coerceLocator );
7759
+ fromType, toType, locatorPtr );
7772
7760
coerceConstraint->setFavored ();
7773
7761
constraints.push_back (coerceConstraint);
7774
7762
Original file line number Diff line number Diff line change @@ -34,7 +34,6 @@ namespace swift {
34
34
35
35
class Expr ;
36
36
class SourceManager ;
37
- class CoerceExpr ;
38
37
39
38
namespace constraints {
40
39
class ConstraintSystem ;
You can’t perform that action at this time.
0 commit comments