Skip to content

Commit 01c22b7

Browse files
authored
Merge pull request #60182 from xedin/rdar-97389698
[ConstraintSystem] Adjust locator for implicit conversions between tu…
2 parents 9a660e1 + d0289dc commit 01c22b7

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,18 @@ ConstraintLocator *ConstraintSystem::getImplicitValueConversionLocator(
452452
anchor = ASTNode();
453453
path.clear();
454454
}
455+
456+
// If conversion is for a tuple element, let's drop `TupleType`
457+
// components from the path since they carry information for
458+
// diagnostics that `ExprRewriter` won't be able to re-construct
459+
// during solution application.
460+
if (!path.empty() && path.back().is<LocatorPathElt::TupleElement>()) {
461+
path.erase(llvm::remove_if(path,
462+
[](const LocatorPathElt &elt) {
463+
return elt.is<LocatorPathElt::TupleType>();
464+
}),
465+
path.end());
466+
}
455467
}
456468

457469
return getConstraintLocator(/*base=*/getConstraintLocator(anchor, path),

test/Constraints/implicit_double_cgfloat_conversion.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,8 @@ func assignment_with_leading_dot_syntax() {
280280
}()
281281
}
282282
}
283+
284+
func test_conversion_inside_tuple_elements() -> (a: CGFloat, b: (c: Int, d: CGFloat)) {
285+
let x: Double = 0.0
286+
return (a: x, b: (c: 42, d: x)) // Ok
287+
}

0 commit comments

Comments
 (0)