Skip to content

Commit 000625f

Browse files
committed
[CSApply] Use correct locator while converting expression to contextual type
This wasn't a problem before since locator wasn't really used by `ExprRewritter:coerceToType` but with Double<->CGFloat conversion it needs the locator to be anchored at a rewritten expression instead of the original one to form a correct implicit initializer call.
1 parent 4f5a8d4 commit 000625f

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

lib/Sema/CSApply.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8554,16 +8554,15 @@ ExprWalker::rewriteTarget(SolutionApplicationTarget target) {
85548554
// If we're supposed to convert the expression to some particular type,
85558555
// do so now.
85568556
if (shouldCoerceToContextualType()) {
8557-
resultExpr = Rewriter.coerceToType(resultExpr,
8558-
solution.simplifyType(convertType),
8559-
cs.getConstraintLocator(expr));
8557+
resultExpr =
8558+
Rewriter.coerceToType(resultExpr, solution.simplifyType(convertType),
8559+
cs.getConstraintLocator(resultExpr));
85608560
} else if (cs.getType(resultExpr)->hasLValueType() &&
85618561
!target.isDiscardedExpr()) {
85628562
// We referenced an lvalue. Load it.
85638563
resultExpr = Rewriter.coerceToType(
8564-
resultExpr,
8565-
cs.getType(resultExpr)->getRValueType(),
8566-
cs.getConstraintLocator(expr));
8564+
resultExpr, cs.getType(resultExpr)->getRValueType(),
8565+
cs.getConstraintLocator(resultExpr));
85678566
}
85688567

85698568
if (!resultExpr)

test/Constraints/implicit_double_cgfloat_conversion.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,20 @@ func test_conversions_with_optionals(v: CGFloat?) {
107107
// CHECK: function_ref @$sSd12CoreGraphicsEySdAA7CGFloatVcfC : $@convention(method) (CGFloat, @thin Double.Type) -> Double
108108
let _: Double = (v ?? 0)
109109
}
110+
111+
func test_static_members_are_contextually_convertible() {
112+
struct S {
113+
static var testProp: CGFloat { 42 }
114+
static func testFunc() -> CGFloat { 42 }
115+
}
116+
117+
func test_prop(s: S) -> Double {
118+
// CHECK: function_ref @$sSd12CoreGraphicsEySdAA7CGFloatVcfC : $@convention(method) (CGFloat, @thin Double.Type) -> Double
119+
return S.testProp // Ok
120+
}
121+
122+
func test_method(s: S) -> Double {
123+
// CHECK: function_ref @$sSd12CoreGraphicsEySdAA7CGFloatVcfC : $@convention(method) (CGFloat, @thin Double.Type) -> Double
124+
return S.testFunc() // Ok
125+
}
126+
}

0 commit comments

Comments
 (0)