Skip to content

Commit 1d1f065

Browse files
committed
[CSApply] Use fully qualified locator while coercing array elements
Double/CGFloat implicit conversion expects a full locator (array-expr + tuple-element <idx>) to find selected overload.
1 parent 19b27c5 commit 1d1f065

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

lib/Sema/CSApply.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3481,9 +3481,11 @@ namespace {
34813481

34823482
auto elementType = expr->getElementType();
34833483

3484-
for (auto &element : expr->getElements()) {
3485-
element = coerceToType(element, elementType,
3486-
cs.getConstraintLocator(element));
3484+
for (unsigned i = 0, n = expr->getNumElements(); i != n; ++i) {
3485+
expr->setElement(
3486+
i, coerceToType(expr->getElement(i), elementType,
3487+
cs.getConstraintLocator(
3488+
expr, {LocatorPathElt::TupleElement(i)})));
34873489
}
34883490

34893491
return expr;

test/Constraints/implicit_double_cgfloat_conversion.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,22 @@ func test_multi_argument_conversion_with_optional(d: Double, cgf: CGFloat) {
216216

217217
test(cgf, d) // Ok (CGFloat -> Double and Double? -> CGFloat?)
218218
}
219+
220+
func test_array_literal_as_call_argument() {
221+
enum E {
222+
case test_arr([CGFloat])
223+
}
224+
225+
struct Container {
226+
var prop: E
227+
}
228+
229+
struct Point {
230+
var x: Double
231+
var y: Double
232+
}
233+
234+
func test(cont: inout Container, point: Point) {
235+
cont.prop = .test_arr([point.x]) // Ok
236+
}
237+
}

0 commit comments

Comments
 (0)