File tree 2 files changed +13
-1
lines changed
2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -7767,7 +7767,16 @@ void ConstraintSystem::addExplicitConversionConstraint(
7767
7767
auto locatorPtr = getConstraintLocator (locator);
7768
7768
7769
7769
// Coercion (the common case).
7770
- auto coerceLocator = getConstraintLocator (locator.getBaseLocator (), LocatorPathElt::TypeCoercion ());
7770
+ auto coerceLocator = [&]() {
7771
+ if (auto expr = dyn_cast<CoerceExpr>(locatorPtr->getAnchor ())) {
7772
+ // Only adding this path for explicty coercions e.g _ = a as Int
7773
+ // and for non lireal subExpr.
7774
+ if (!expr->isImplicit () && !isa<LiteralExpr>(expr->getSubExpr ()))
7775
+ return getConstraintLocator (locator.getBaseLocator (), LocatorPathElt::TypeCoercion ());
7776
+ }
7777
+ return locatorPtr;
7778
+ }();
7779
+
7771
7780
Constraint *coerceConstraint =
7772
7781
Constraint::create (*this , ConstraintKind::Conversion,
7773
7782
fromType, toType, coerceLocator);
Original file line number Diff line number Diff line change @@ -150,3 +150,6 @@ _ = sr11295c as String // expected-warning {{casting expression to 'String' does
150
150
151
151
let sr11295d = " Hello Typealias "
152
152
_ = sr11295d as Type // expected-warning {{casting expression to 'Type' (aka 'String') doesn't change the type}} {{14-22=}}
153
+
154
+ _ = " Hello " as String // Ok
155
+ _ = 1 as Int64 // Ok
You can’t perform that action at this time.
0 commit comments