Skip to content

Commit 683c4a0

Browse files
committed
Sema: Allow optional-to-optional CGFloat <-> Double conversion
1 parent 0035420 commit 683c4a0

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7388,28 +7388,18 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
73887388
// Look through all value-to-optional promotions to allow
73897389
// conversions like Double -> CGFloat?? and vice versa.
73907390
// T -> Optional<T>
7391-
if (location.endsWith<LocatorPathElt::OptionalPayload>()) {
7391+
if (location.endsWith<LocatorPathElt::OptionalPayload>() ||
7392+
location.endsWith<LocatorPathElt::GenericArgument>()) {
73927393
SmallVector<LocatorPathElt, 4> path;
73937394
auto anchor = location.getLocatorParts(path);
73947395

7395-
// An attempt at Double/CGFloat conversion through
7396-
// optional chaining. This is not supported at the
7397-
// moment because solution application doesn't know
7398-
// how to map Double to/from CGFloat through optionals.
7399-
if (isExpr<OptionalEvaluationExpr>(anchor)) {
7400-
if (!shouldAttemptFixes())
7401-
return getTypeMatchFailure(locator);
7402-
7403-
conversionsOrFixes.push_back(ContextualMismatch::create(
7404-
*this, nominal1, nominal2, getConstraintLocator(locator)));
7405-
break;
7406-
}
7407-
7408-
// Drop all of the applied `value-to-optional` promotions.
7396+
// Drop all of the applied `value-to-optional` and
7397+
// `optional-to-optional` conversions.
74097398
path.erase(llvm::remove_if(
74107399
path,
74117400
[](const LocatorPathElt &elt) {
7412-
return elt.is<LocatorPathElt::OptionalPayload>();
7401+
return elt.is<LocatorPathElt::OptionalPayload>() ||
7402+
elt.is<LocatorPathElt::GenericArgument>();
74137403
}),
74147404
path.end());
74157405

@@ -14813,7 +14803,8 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
1481314803
simplifyLocator(anchor, path, range);
1481414804

1481514805
if (path.empty() || llvm::all_of(path, [](const LocatorPathElt &elt) {
14816-
return elt.is<LocatorPathElt::OptionalPayload>();
14806+
return elt.is<LocatorPathElt::OptionalPayload>() ||
14807+
elt.is<LocatorPathElt::GenericArgument>();
1481714808
})) {
1481814809
if (auto *expr = getAsExpr(anchor))
1481914810
if (auto depth = getExprDepth(expr))

0 commit comments

Comments
 (0)