Skip to content

Commit 0e168cb

Browse files
[WIP] checkpoint
1 parent 3c10e7d commit 0e168cb

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

lib/Sema/CSApply.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3525,12 +3525,12 @@ namespace {
35253525
// Turn the subexpression into an rvalue.
35263526
auto rvalueSub = cs.coerceToRValue(expr->getSubExpr());
35273527
expr->setSubExpr(rvalueSub);
3528-
3529-
auto *locator = cs.getConstraintLocator(expr);
3530-
3528+
35313529
// If we weren't explicitly told by the caller which disjunction choice,
35323530
// get it from the solution to determine whether we've picked a coercion
35333531
// or a bridging conversion.
3532+
auto *locator = cs.getConstraintLocator(expr);
3533+
35343534
if (!choice) {
35353535
choice = solution.getDisjunctionChoice(locator);
35363536
}

lib/Sema/CSSimplify.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2797,6 +2797,20 @@ ConstraintSystem::TypeMatchResult
27972797
ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
27982798
TypeMatchOptions flags,
27992799
ConstraintLocatorBuilder locator) {
2800+
2801+
if (!type1->isTypeVariableOrMember()
2802+
&& !type2->isTypeVariableOrMember()
2803+
&& type1->isEqual(type2)) {
2804+
if (locator.getBaseLocator()->
2805+
isLastElement(ConstraintLocator::PathElementKind::ExplicityTypeCoercion)) {
2806+
if (!hasFixFor(locator.getBaseLocator())) {
2807+
auto *fix = RemoveUnecessaryCoercion::create(*this, type2,
2808+
locator.getBaseLocator());
2809+
recordFix(fix);
2810+
}
2811+
}
2812+
}
2813+
28002814
// If we have type variables that have been bound to fixed types, look through
28012815
// to the fixed type.
28022816
type1 = getFixedTypeRecursive(type1, flags, kind == ConstraintKind::Equal);
@@ -2806,15 +2820,9 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
28062820
auto desugar2 = type2->getDesugaredType();
28072821

28082822
// If the types are obviously equivalent, we're done.
2809-
if (desugar1->isEqual(desugar2)) {
2810-
if (locator.getBaseLocator()->
2811-
isLastElement(ConstraintLocator::PathElementKind::ExplicityTypeCoercion)) {
2812-
auto *fix = RemoveUnecessaryCoercion::create(*this, type2,
2813-
locator.getBaseLocator());
2814-
recordFix(fix);
2815-
}
2816-
if (!isa<InOutType>(desugar2))
2817-
return getTypeMatchSuccess();
2823+
if (desugar1->isEqual(desugar2)
2824+
&& !isa<InOutType>(desugar2)) {
2825+
return getTypeMatchSuccess();
28182826
}
28192827

28202828
// Local function that should be used to produce the return value whenever
@@ -7756,10 +7764,7 @@ void ConstraintSystem::addExplicitConversionConstraint(
77567764
auto coerceLocator = [&]() {
77577765
if (auto expr = dyn_cast_or_null<CoerceExpr>(locatorPtr->getAnchor())) {
77587766
// Only adding this path for explicty coercions e.g _ = a as Int
7759-
// and for non literal/array-literal subExpr.
7760-
if (!expr->isImplicit()
7761-
&& !isa<LiteralExpr>(expr->getSubExpr())
7762-
&& !isa<CollectionExpr>(expr->getSubExpr()))
7767+
if (!expr->isImplicit())
77637768
return getConstraintLocator(expr, LocatorPathElt::ExplicitTypeCoercion());
77647769
}
77657770
return locatorPtr;

0 commit comments

Comments
 (0)