diff --git a/lib/Sema/ConstraintSystem.cpp b/lib/Sema/ConstraintSystem.cpp index bd96d3951b2..59bd14518ae 100644 --- a/lib/Sema/ConstraintSystem.cpp +++ b/lib/Sema/ConstraintSystem.cpp @@ -452,6 +452,18 @@ ConstraintLocator *ConstraintSystem::getImplicitValueConversionLocator( anchor = ASTNode(); path.clear(); } + + // If conversion is for a tuple element, let's drop `TupleType` + // components from the path since they carry information for + // diagnostics that `ExprRewriter` won't be able to re-construct + // during solution application. + if (!path.empty() && path.back().is()) { + path.erase(llvm::remove_if(path, + [](const LocatorPathElt &elt) { + return elt.is(); + }), + path.end()); + } } return getConstraintLocator(/*base=*/getConstraintLocator(anchor, path), diff --git a/test/Constraints/implicit_double_cgfloat_conversion.swift b/test/Constraints/implicit_double_cgfloat_conversion.swift index 6f0c1b8af47..8f1ce576644 100644 --- a/test/Constraints/implicit_double_cgfloat_conversion.swift +++ b/test/Constraints/implicit_double_cgfloat_conversion.swift @@ -280,3 +280,8 @@ func assignment_with_leading_dot_syntax() { }() } } + +func test_conversion_inside_tuple_elements() -> (a: CGFloat, b: (c: Int, d: CGFloat)) { + let x: Double = 0.0 + return (a: x, b: (c: 42, d: x)) // Ok +}