Skip to content

Commit 074035b

Browse files
committed
[CSApply] Use fully qualified locator while coercing dictionary elements
Just like in case of array elements, the locator needs to much what was produced by constraint generator otherwise Double<->CGFloat implicit coercion wouldn't be able to find the overload choice.
1 parent 5432c34 commit 074035b

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

lib/Sema/CSApply.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3528,9 +3528,12 @@ namespace {
35283528
expr->setInitializer(witness);
35293529

35303530
auto elementType = expr->getElementType();
3531-
for (auto &element : expr->getElements()) {
3532-
element = coerceToType(element, elementType,
3533-
cs.getConstraintLocator(element));
3531+
3532+
for (unsigned i = 0, n = expr->getNumElements(); i != n; ++i) {
3533+
expr->setElement(
3534+
i, coerceToType(expr->getElement(i), elementType,
3535+
cs.getConstraintLocator(
3536+
expr, {LocatorPathElt::TupleElement(i)})));
35343537
}
35353538

35363539
return expr;

test/Constraints/implicit_double_cgfloat_conversion.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,17 @@ func test_multi_argument_conversion_with_optional(d: Double, cgf: CGFloat) {
217217
test(cgf, d) // Ok (CGFloat -> Double and Double? -> CGFloat?)
218218
}
219219

220-
func test_array_literal_as_call_argument() {
220+
extension CGFloat: Hashable {
221+
public func hash(into hasher: inout Hasher) { fatalError() }
222+
}
223+
224+
func test_collection_literals_as_call_arguments() {
221225
enum E {
222226
case test_arr([CGFloat])
227+
case test_dict_key([CGFloat: String])
228+
case test_dict_value([String: CGFloat])
229+
case test_arr_nested([String: [[CGFloat]: String]])
230+
case test_dict_nested([String: [String: CGFloat]])
223231
}
224232

225233
struct Container {
@@ -233,5 +241,9 @@ func test_array_literal_as_call_argument() {
233241

234242
func test(cont: inout Container, point: Point) {
235243
cont.prop = .test_arr([point.x]) // Ok
244+
cont.prop = .test_dict_key([point.y: ""]) // Ok
245+
cont.prop = .test_dict_value(["": point.y]) // Ok
246+
cont.prop = .test_arr_nested(["": [[point.x]: ""]]) // Ok
247+
cont.prop = .test_dict_nested(["": ["": point.x]]) // Ok
236248
}
237249
}

0 commit comments

Comments
 (0)