|
| 1 | +// RUN: %target-typecheck-verify-swift -language-mode 6 -verify-additional-prefix swift6- |
| 2 | +// RUN: %target-typecheck-verify-swift -language-mode 7 -verify-additional-prefix swift7- |
| 3 | +// REQUIRES: swift7 |
| 4 | + |
| 5 | +func testTupleLabelMismatchFuncConversion(fn1: @escaping ((x: Int, y: Int)) -> Void, |
| 6 | + fn2: @escaping () -> (x: Int, Int)) { |
| 7 | + // Warn on mismatches in Swift 6, upgrading to an error for Swift 7 |
| 8 | + let _: ((a: Int, b: Int)) -> Void = fn1 |
| 9 | + // expected-swift6-warning@-1 {{tuple conversion from '(a: Int, b: Int)' to '(x: Int, y: Int)' mismatches labels}} |
| 10 | + // expected-swift7-error@-2 {{tuple conversion from '(a: Int, b: Int)' to '(x: Int, y: Int)' mismatches labels}} |
| 11 | + let _: ((x: Int, b: Int)) -> Void = fn1 |
| 12 | + // expected-swift6-warning@-1 {{tuple conversion from '(x: Int, b: Int)' to '(x: Int, y: Int)' mismatches labels}} |
| 13 | + // expected-swift7-error@-2 {{tuple conversion from '(x: Int, b: Int)' to '(x: Int, y: Int)' mismatches labels}} |
| 14 | + |
| 15 | + let _: () -> (y: Int, Int) = fn2 |
| 16 | + // expected-swift6-warning@-1 {{tuple conversion from '(x: Int, Int)' to '(y: Int, Int)' mismatches labels}} |
| 17 | + // expected-swift7-error@-2 {{tuple conversion from '(x: Int, Int)' to '(y: Int, Int)' mismatches labels}} |
| 18 | + let _: () -> (y: Int, k: Int) = fn2 |
| 19 | + // expected-swift6-warning@-1 {{tuple conversion from '(x: Int, Int)' to '(y: Int, k: Int)' mismatches labels}} |
| 20 | + // expected-swift7-error@-2 {{tuple conversion from '(x: Int, Int)' to '(y: Int, k: Int)' mismatches labels}} |
| 21 | + |
| 22 | + // Attempting to shuffle has always been illegal here |
| 23 | + let _: () -> (y: Int, x: Int) = fn2 |
| 24 | + // expected-error@-1 {{cannot convert value of type '() -> (x: Int, Int)' to specified type '() -> (y: Int, x: Int)'}} |
| 25 | + |
| 26 | + // Losing labels is okay though. |
| 27 | + let _: () -> (Int, Int) = fn2 |
| 28 | + |
| 29 | + // Gaining labels also okay. |
| 30 | + let _: ((x: Int, Int)) -> Void = fn1 |
| 31 | + let _: () -> (x: Int, y: Int) = fn2 |
| 32 | + let _: () -> (Int, y: Int) = fn2 |
| 33 | +} |
0 commit comments