|
| 1 | +// RUN: %target-typecheck-verify-swift -disable-parser-lookup |
| 2 | + |
| 3 | +func valid1() { |
| 4 | + func inner(_: Int) {} |
| 5 | + func inner(_: String) {} |
| 6 | + |
| 7 | + func inner(label: Int) {} |
| 8 | + func inner(label: String) {} |
| 9 | + |
| 10 | + inner(123) |
| 11 | + inner("hello") |
| 12 | + |
| 13 | + inner(label: 123) |
| 14 | + inner(label: "hello") |
| 15 | +} |
| 16 | + |
| 17 | +func valid2() { |
| 18 | + func inner(_: Int = 0) {} |
| 19 | + func inner() -> Bool {} |
| 20 | + func inner(first: Int, second: Int = 0) {} |
| 21 | + |
| 22 | + let _: Bool = inner() |
| 23 | + let _ = inner() |
| 24 | + |
| 25 | + inner(first: 123) |
| 26 | +} |
| 27 | + |
| 28 | +func invalid1() { |
| 29 | + func inner(_: Int) {} |
| 30 | + // expected-note@-1 {{'inner' previously declared here}} |
| 31 | + func inner(_: Int) {} |
| 32 | + // expected-error@-1 {{invalid redeclaration of 'inner'}} |
| 33 | +} |
| 34 | + |
| 35 | +func invalid2() { |
| 36 | + func inner(_: Int) {} |
| 37 | + // expected-note@-1 {{candidate expects value of type 'Int' for parameter #1}} |
| 38 | + // expected-note@-2 {{found this candidate}} |
| 39 | + // expected-note@-3 {{did you mean 'inner'?}} |
| 40 | + func inner(_: String) {} |
| 41 | + // expected-note@-1 {{candidate expects value of type 'String' for parameter #1}} |
| 42 | + // expected-note@-2 {{found this candidate}} |
| 43 | + // expected-note@-3 {{did you mean 'inner'?}} |
| 44 | + |
| 45 | + func inner(label: Int) {} |
| 46 | + // expected-note@-1 {{found this candidate}} |
| 47 | + // expected-note@-2 {{did you mean 'inner'?}} |
| 48 | + |
| 49 | + inner([]) |
| 50 | + // expected-error@-1 {{no exact matches in call to local function 'inner'}} |
| 51 | + |
| 52 | + inner(label: "hi") |
| 53 | + // expected-error@-1 {{cannot convert value of type 'String' to expected argument type 'Int'}} |
| 54 | + |
| 55 | + _ = inner |
| 56 | + // expected-error@-1 {{ambiguous use of 'inner'}} |
| 57 | + |
| 58 | + _ = inner(label:) // no-error |
| 59 | + |
| 60 | + // FIXME: This isn't as good as in the non-local function case? |
| 61 | + _ = inner(invalidLabel:) |
| 62 | + // expected-error@-1 {{cannot find 'inner(invalidLabel:)' in scope}} |
| 63 | +} |
0 commit comments