Skip to content

Commit 53ce55a

Browse files
committed
[CSApply] Use fully qualified locator while coercing member chain result
Constraint generator records conversion between chain result expression and contextual type as anchored on an implicit unresolved chain result, which means that coercion has to do the same in case restrictions (like Double<->CGFloat conversion) depend on locators to retrieve information for the solution. Resolves: rdar://97261826
1 parent 9a38146 commit 53ce55a

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/Sema/CSApply.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3466,7 +3466,10 @@ namespace {
34663466
// type.
34673467
auto *subExpr = expr->getSubExpr();
34683468
auto type = simplifyType(cs.getType(expr));
3469-
subExpr = coerceToType(subExpr, type, cs.getConstraintLocator(subExpr));
3469+
subExpr = coerceToType(
3470+
subExpr, type,
3471+
cs.getConstraintLocator(
3472+
expr, ConstraintLocator::UnresolvedMemberChainResult));
34703473
cs.setType(subExpr, type);
34713474
return subExpr;
34723475
}

test/Constraints/implicit_double_cgfloat_conversion.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,21 @@ func assignments_with_and_without_optionals() {
262262
copy.prop = (true ? cgf : (false ? v : cgf))
263263
}
264264
}
265+
266+
extension CGFloat {
267+
static let `default` = 42.0
268+
}
269+
270+
// rdar://97261826 - crash during constraint application with leading-dot syntax
271+
func assignment_with_leading_dot_syntax() {
272+
class Container {
273+
var prop: CGFloat = 0
274+
}
275+
276+
struct Test {
277+
let test: Void = {
278+
let c = Container()
279+
c.prop = .default // Ok (Double -> CGFloat)
280+
}()
281+
}
282+
}

0 commit comments

Comments
 (0)