Skip to content

Commit 05d3c4b

Browse files
authored
Merge pull request #22783 from slavapestov/fix-swift-4-tuple-arguments-hack
Sema: Fix inconsistent behavior with SE-0110-related compatibility hack
2 parents 54ec06d + 6d19f7e commit 05d3c4b

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,10 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
11841184
// We somehow let tuple unsplatting function conversions
11851185
// through in some cases in Swift 4, so let's let that
11861186
// continue to work, but only for Swift 4.
1187-
if (simplified && isa<DeclRefExpr>(simplified)) {
1187+
if (simplified &&
1188+
(isa<DeclRefExpr>(simplified) ||
1189+
isa<OverloadedDeclRefExpr>(simplified) ||
1190+
isa<UnresolvedDeclRefExpr>(simplified))) {
11881191
implodeParams(func2Params);
11891192
}
11901193
}

test/Compatibility/tuple_arguments_4.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,10 +1642,17 @@ public extension Optional {
16421642
}
16431643

16441644
// https://bugs.swift.org/browse/SR-6837
1645+
1646+
// FIXME: Can't overlaod local functions so these must be top-level
1647+
func takePairOverload(_ pair: (Int, Int?)) {}
1648+
func takePairOverload(_: () -> ()) {}
1649+
16451650
do {
16461651
func takeFn(fn: (_ i: Int, _ j: Int?) -> ()) {}
16471652
func takePair(_ pair: (Int, Int?)) {}
16481653
takeFn(fn: takePair) // Allow for -swift-version 4, but not later
1654+
takeFn(fn: takePairOverload) // Allow for -swift-version 4, but not later
1655+
16491656
takeFn(fn: { (pair: (Int, Int?)) in } ) // Disallow for -swift-version 4 and later
16501657
// expected-error@-1 {{contextual closure type '(Int, Int?) -> ()' expects 2 arguments, but 1 was used in closure body}}
16511658
takeFn { (pair: (Int, Int?)) in } // Disallow for -swift-version 4 and later

test/Constraints/tuple_arguments.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,10 +1645,16 @@ public extension Optional {
16451645
}
16461646

16471647
// https://bugs.swift.org/browse/SR-6837
1648+
1649+
// FIXME: Can't overlaod local functions so these must be top-level
1650+
func takePairOverload(_ pair: (Int, Int?)) {} // expected-note {{found this candidate}}
1651+
func takePairOverload(_: () -> ()) {} // expected-note {{found this candidate}}
1652+
16481653
do {
16491654
func takeFn(fn: (_ i: Int, _ j: Int?) -> ()) {}
16501655
func takePair(_ pair: (Int, Int?)) {}
16511656
takeFn(fn: takePair) // expected-error {{cannot convert value of type '((Int, Int?)) -> ()' to expected argument type '(Int, Int?) -> ()'}}
1657+
takeFn(fn: takePairOverload) // expected-error {{ambiguous reference to member 'takePairOverload'}}
16521658
takeFn(fn: { (pair: (Int, Int?)) in } ) // Disallow for -swift-version 4 and later
16531659
// expected-error@-1 {{contextual closure type '(Int, Int?) -> ()' expects 2 arguments, but 1 was used in closure body}}
16541660
takeFn { (pair: (Int, Int?)) in } // Disallow for -swift-version 4 and later

0 commit comments

Comments
 (0)