Skip to content

Commit 78ae8de

Browse files
committed
[CSApply] Make sure to load value before attempting implicit conversion
1 parent fbeca3d commit 78ae8de

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/Sema/CSApply.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6697,6 +6697,9 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
66976697
auto *argExpr = locator.trySimplifyToExpr();
66986698
assert(argExpr);
66996699

6700+
// Load the value for conversion.
6701+
argExpr = cs.coerceToRValue(argExpr);
6702+
67006703
auto *implicitInit =
67016704
CallExpr::createImplicit(ctx, TypeExpr::createImplicit(toType, ctx),
67026705
/*args=*/{argExpr},

test/Misc/misc_diagnostics.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,12 @@ func test_implicit_cgfloat_conversion() {
220220

221221
let c: Double = (a ?? 0) as CGFloat // Ok with implicit conversion
222222
}
223+
224+
func test_loading_tuple_elements(values: inout (CGFloat, CGFloat)) {
225+
struct S {
226+
init(x: Double, y: Double) {}
227+
init(x: CGFloat, y: CGFloat) {}
228+
}
229+
_ = S(x: 0.0, y: values.0) // Ok
230+
}
223231
}

0 commit comments

Comments
 (0)