Skip to content

Commit 35077a0

Browse files
committed
Revert "Sema: Allow optional-to-optional CGFloat <-> Double conversion"
This reverts commit f0f5ffc.
1 parent 367e5e2 commit 35077a0

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7489,18 +7489,28 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
74897489
// Look through all value-to-optional promotions to allow
74907490
// conversions like Double -> CGFloat?? and vice versa.
74917491
// T -> Optional<T>
7492-
if (location.endsWith<LocatorPathElt::OptionalInjection>() ||
7493-
location.endsWith<LocatorPathElt::GenericArgument>()) {
7492+
if (location.endsWith<LocatorPathElt::OptionalInjection>()) {
74947493
SmallVector<LocatorPathElt, 4> path;
74957494
auto anchor = location.getLocatorParts(path);
74967495

7497-
// Drop all of the applied `value-to-optional` and
7498-
// `optional-to-optional` conversions.
7496+
// An attempt at Double/CGFloat conversion through
7497+
// optional chaining. This is not supported at the
7498+
// moment because solution application doesn't know
7499+
// how to map Double to/from CGFloat through optionals.
7500+
if (isExpr<OptionalEvaluationExpr>(anchor)) {
7501+
if (!shouldAttemptFixes())
7502+
return getTypeMatchFailure(locator);
7503+
7504+
conversionsOrFixes.push_back(ContextualMismatch::create(
7505+
*this, nominal1, nominal2, getConstraintLocator(locator)));
7506+
break;
7507+
}
7508+
7509+
// Drop all of the applied `value-to-optional` promotions.
74997510
path.erase(llvm::remove_if(
75007511
path,
75017512
[](const LocatorPathElt &elt) {
7502-
return elt.is<LocatorPathElt::OptionalInjection>() ||
7503-
elt.is<LocatorPathElt::GenericArgument>();
7513+
return elt.is<LocatorPathElt::OptionalInjection>();
75047514
}),
75057515
path.end());
75067516

test/Constraints/implicit_double_cgfloat_conversion.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,3 @@ func test_init_validation() {
349349
}
350350
}
351351
}
352-
353-
// Optional-to-optional conversion
354-
func optional_to_optional(x: CGFloat?) -> Double? {
355-
return x
356-
}

validation-test/Sema/type_checker_crashers_fixed/rdar83666783.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ func compute(_: Double?) -> Double? {
1212
}
1313

1414
func test(s: S?) {
15-
_ = compute(s?.test)
15+
_ = compute(s?.test) // expected-error {{cannot implicitly convert value of type 'CGFloat?' to expected type 'Double?'}}
1616
}

0 commit comments

Comments
 (0)