Sema: Allow optional-to-optional CGFloat <-> Double conversion

After https://github.com/swiftlang/swift/pull/78957, there is no
technical reason to not allow this conversion. This is needed for
an upcoming optimization.
This commit is contained in:
Slava Pestov
2025-01-27 16:39:06 -05:00
parent 725bd910be
commit f0f5ffcebf
3 changed files with 12 additions and 17 deletions

View File

@@ -7392,28 +7392,18 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
// Look through all value-to-optional promotions to allow
// conversions like Double -> CGFloat?? and vice versa.
// T -> Optional<T>
if (location.endsWith<LocatorPathElt::OptionalPayload>()) {
if (location.endsWith<LocatorPathElt::OptionalPayload>() ||
location.endsWith<LocatorPathElt::GenericArgument>()) {
SmallVector<LocatorPathElt, 4> path;
auto anchor = location.getLocatorParts(path);
// An attempt at Double/CGFloat conversion through
// optional chaining. This is not supported at the
// moment because solution application doesn't know
// how to map Double to/from CGFloat through optionals.
if (isExpr<OptionalEvaluationExpr>(anchor)) {
if (!shouldAttemptFixes())
return getTypeMatchFailure(locator);
conversionsOrFixes.push_back(ContextualMismatch::create(
*this, nominal1, nominal2, getConstraintLocator(locator)));
break;
}
// Drop all of the applied `value-to-optional` promotions.
// Drop all of the applied `value-to-optional` and
// `optional-to-optional` conversions.
path.erase(llvm::remove_if(
path,
[](const LocatorPathElt &elt) {
return elt.is<LocatorPathElt::OptionalPayload>();
return elt.is<LocatorPathElt::OptionalPayload>() ||
elt.is<LocatorPathElt::GenericArgument>();
}),
path.end());