Skip to content

[CSApply] Fix source breakage related to deep-equality types and SE-0110 #12934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6000,9 +6000,40 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
toTuple->getElementForScalarInit(), locator);
}

case ConversionRestrictionKind::DeepEquality:
assert(toType->hasUnresolvedType() && "Should have handled this above");
break;
case ConversionRestrictionKind::DeepEquality: {
if (toType->hasUnresolvedType())
break;

// HACK: Fix problem related to Swift 3 mode (with assertions),
// since Swift 3 mode allows passing arguments with extra parens
// to parameters which don't expect them, it should be supported
// by "deep equality" type - Optional<T> e.g.
// ```swift
// func foo(_: (() -> Void)?) {}
// func bar() -> ((()) -> Void)? { return nil }
// foo(bar) // This expression should compile in Swift 3 mode
// ```
if (tc.getLangOpts().isSwiftVersion3()) {
auto obj1 = fromType->getAnyOptionalObjectType();
auto obj2 = toType->getAnyOptionalObjectType();

if (obj1 && obj2) {
auto *fn1 = obj1->getAs<AnyFunctionType>();
auto *fn2 = obj2->getAs<AnyFunctionType>();

if (fn1 && fn2) {
auto *params1 = fn1->getInput()->getAs<TupleType>();
auto *params2 = fn2->getInput()->getAs<TupleType>();

// This handles situations like argument: (()), parameter: ().
if (params1 && params2 && params1->isEqual(params2))
break;
}
}
}

llvm_unreachable("Should be handled above");
}

case ConversionRestrictionKind::Superclass:
return coerceSuperclass(expr, toType, locator);
Expand Down
7 changes: 7 additions & 0 deletions test/Compatibility/tuple_arguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1486,3 +1486,10 @@ rdar32301091_1 { _ in } // Ok in Swift 3

func rdar32301091_2(_ :(Int, Int) -> ()) {}
rdar32301091_2 { _ in } // Ok in Swift 3

// rdar://problem/35198459 - source-compat-suite failure: Moya (toType->hasUnresolvedType() && "Should have handled this above")
do {
func foo(_: (() -> Void)?) {}
func bar() -> ((()) -> Void)? { return nil }
foo(bar()) // OK in Swift 3 mode
}
7 changes: 7 additions & 0 deletions test/Constraints/tuple_arguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1621,3 +1621,10 @@ func rdar33239714() {
Generic<(Int, Int)>().optAliasF { x, y in }
Generic<(Int, Int)>().optAliasF { (x, y) in }
}

// rdar://problem/35198459 - source-compat-suite failure: Moya (toType->hasUnresolvedType() && "Should have handled this above"
do {
func foo(_: (() -> Void)?) {}
func bar() -> ((()) -> Void)? { return nil }
foo(bar()) // expected-error {{cannot convert value of type '((()) -> Void)?' to expected argument type '(() -> Void)?'}}
}