Skip to content

Commit 5660de8

Browse files
Updating check location.
1 parent 666190c commit 5660de8

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

lib/Sema/CSApply.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3525,12 +3525,20 @@ namespace {
35253525
// Turn the subexpression into an rvalue.
35263526
auto rvalueSub = cs.coerceToRValue(expr->getSubExpr());
35273527
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+
35293539
// If we weren't explicitly told by the caller which disjunction choice,
35303540
// get it from the solution to determine whether we've picked a coercion
35313541
// or a bridging conversion.
3532-
auto *locator = cs.getConstraintLocator(expr);
3533-
35343542
if (!choice) {
35353543
choice = solution.getDisjunctionChoice(locator);
35363544
}

lib/Sema/CSGen.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2661,7 +2661,15 @@ namespace {
26612661
CS.setType(expr->getCastTypeLoc(), toType);
26622662

26632663
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+
}();
26652673

26662674
// Add a conversion constraint for the direct conversion between
26672675
// types.
@@ -2672,7 +2680,7 @@ namespace {
26722680
// bindings for the result of the coercion.
26732681
auto *TR = expr->getCastTypeLoc().getTypeRepr();
26742682
if (TR && TR->getKind() == TypeReprKind::ImplicitlyUnwrappedOptional)
2675-
return createTypeVariableAndDisjunctionForIUOCoercion(toType, locator);
2683+
return createTypeVariableAndDisjunctionForIUOCoercion(toType, CS.getConstraintLocator(expr));
26762684

26772685
return toType;
26782686
}

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7754,21 +7754,9 @@ void ConstraintSystem::addExplicitConversionConstraint(
77547754
auto locatorPtr = getConstraintLocator(locator);
77557755

77567756
// 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-
77697757
Constraint *coerceConstraint =
77707758
Constraint::create(*this, ConstraintKind::Conversion,
7771-
fromType, toType, coerceLocator);
7759+
fromType, toType, locatorPtr);
77727760
coerceConstraint->setFavored();
77737761
constraints.push_back(coerceConstraint);
77747762

lib/Sema/ConstraintLocator.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ namespace swift {
3434

3535
class Expr;
3636
class SourceManager;
37-
class CoerceExpr;
3837

3938
namespace constraints {
4039
class ConstraintSystem;

0 commit comments

Comments
 (0)