Skip to content

Commit 92e2a25

Browse files
authored
Merge pull request #12934 from xedin/rdar-35198459
[CSApply] Fix source breakage related to deep-equality types and SE-0110
2 parents 3f72b03 + 05d524d commit 92e2a25

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

lib/Sema/CSApply.cpp

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6000,9 +6000,40 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
60006000
toTuple->getElementForScalarInit(), locator);
60016001
}
60026002

6003-
case ConversionRestrictionKind::DeepEquality:
6004-
assert(toType->hasUnresolvedType() && "Should have handled this above");
6005-
break;
6003+
case ConversionRestrictionKind::DeepEquality: {
6004+
if (toType->hasUnresolvedType())
6005+
break;
6006+
6007+
// HACK: Fix problem related to Swift 3 mode (with assertions),
6008+
// since Swift 3 mode allows passing arguments with extra parens
6009+
// to parameters which don't expect them, it should be supported
6010+
// by "deep equality" type - Optional<T> e.g.
6011+
// ```swift
6012+
// func foo(_: (() -> Void)?) {}
6013+
// func bar() -> ((()) -> Void)? { return nil }
6014+
// foo(bar) // This expression should compile in Swift 3 mode
6015+
// ```
6016+
if (tc.getLangOpts().isSwiftVersion3()) {
6017+
auto obj1 = fromType->getAnyOptionalObjectType();
6018+
auto obj2 = toType->getAnyOptionalObjectType();
6019+
6020+
if (obj1 && obj2) {
6021+
auto *fn1 = obj1->getAs<AnyFunctionType>();
6022+
auto *fn2 = obj2->getAs<AnyFunctionType>();
6023+
6024+
if (fn1 && fn2) {
6025+
auto *params1 = fn1->getInput()->getAs<TupleType>();
6026+
auto *params2 = fn2->getInput()->getAs<TupleType>();
6027+
6028+
// This handles situations like argument: (()), parameter: ().
6029+
if (params1 && params2 && params1->isEqual(params2))
6030+
break;
6031+
}
6032+
}
6033+
}
6034+
6035+
llvm_unreachable("Should be handled above");
6036+
}
60066037

60076038
case ConversionRestrictionKind::Superclass:
60086039
return coerceSuperclass(expr, toType, locator);

test/Compatibility/tuple_arguments.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,3 +1486,10 @@ rdar32301091_1 { _ in } // Ok in Swift 3
14861486

14871487
func rdar32301091_2(_ :(Int, Int) -> ()) {}
14881488
rdar32301091_2 { _ in } // Ok in Swift 3
1489+
1490+
// rdar://problem/35198459 - source-compat-suite failure: Moya (toType->hasUnresolvedType() && "Should have handled this above")
1491+
do {
1492+
func foo(_: (() -> Void)?) {}
1493+
func bar() -> ((()) -> Void)? { return nil }
1494+
foo(bar()) // OK in Swift 3 mode
1495+
}

test/Constraints/tuple_arguments.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,3 +1621,10 @@ func rdar33239714() {
16211621
Generic<(Int, Int)>().optAliasF { x, y in }
16221622
Generic<(Int, Int)>().optAliasF { (x, y) in }
16231623
}
1624+
1625+
// rdar://problem/35198459 - source-compat-suite failure: Moya (toType->hasUnresolvedType() && "Should have handled this above"
1626+
do {
1627+
func foo(_: (() -> Void)?) {}
1628+
func bar() -> ((()) -> Void)? { return nil }
1629+
foo(bar()) // expected-error {{cannot convert value of type '((()) -> Void)?' to expected argument type '(() -> Void)?'}}
1630+
}

0 commit comments

Comments
 (0)