|
| 1 | +// RUN: %target-typecheck-verify-swift |
| 2 | + |
| 3 | +// Per rdar://problem/32316666 , it is a common mistake for beginners |
| 4 | +// to start a function name with a number, so it's worth |
| 5 | +// special-casing the diagnostic to make it clearer. |
| 6 | + |
| 7 | +func 1() {} |
| 8 | +// expected-error@-1 {{function name can only start with a letter or underscore, not a number}} |
| 9 | +func 2.0() {} |
| 10 | +// expected-error@-1 {{function name can only start with a letter or underscore, not a number}} |
| 11 | +func 3func() {} |
| 12 | +// expected-error@-1 {{function name can only start with a letter or underscore, not a number}} |
| 13 | +// expected-error@-2 {{expected a digit after integer literal prefix}} |
| 14 | + |
| 15 | +protocol 4 { |
| 16 | + // expected-error@-1 {{protocol name can only start with a letter or underscore, not a number}} |
| 17 | + associatedtype 5 |
| 18 | + // expected-error@-1 {{associatedtype name can only start with a letter or underscore, not a number}} |
| 19 | +} |
| 20 | +protocol 6.0 { |
| 21 | + // expected-error@-1 {{protocol name can only start with a letter or underscore, not a number}} |
| 22 | + associatedtype 7.0 |
| 23 | + // expected-error@-1 {{associatedtype name can only start with a letter or underscore, not a number}} |
| 24 | +} |
| 25 | +protocol 8protocol { |
| 26 | + // expected-error@-1 {{protocol name can only start with a letter or underscore, not a number}} |
| 27 | + // expected-error@-2 {{expected a digit after integer literal prefix}} |
| 28 | + associatedtype 9associatedtype |
| 29 | + // expected-error@-1 {{associatedtype name can only start with a letter or underscore, not a number}} |
| 30 | + // expected-error@-2 {{expected a digit after integer literal prefix}} |
| 31 | +} |
| 32 | + |
| 33 | +typealias 10 = Int |
| 34 | +// expected-error@-1 {{typealias name can only start with a letter or underscore, not a number}} |
| 35 | +typealias 11.0 = Int |
| 36 | +// expected-error@-1 {{typealias name can only start with a letter or underscore, not a number}} |
| 37 | +typealias 12typealias = Int |
| 38 | +// expected-error@-1 {{typealias name can only start with a letter or underscore, not a number}} |
| 39 | +// expected-error@-2 {{expected a digit after integer literal prefix}} |
| 40 | + |
| 41 | +struct 13 {} |
| 42 | +// expected-error@-1 {{struct name can only start with a letter or underscore, not a number}} |
| 43 | +struct 14.0 {} |
| 44 | +// expected-error@-1 {{struct name can only start with a letter or underscore, not a number}} |
| 45 | +struct 15struct {} |
| 46 | +// expected-error@-1 {{struct name can only start with a letter or underscore, not a number}} |
| 47 | +// expected-error@-2 {{expected a digit after integer literal prefix}} |
| 48 | + |
| 49 | +enum 16 {} |
| 50 | +// expected-error@-1 {{enum name can only start with a letter or underscore, not a number}} |
| 51 | +enum 17.0 {} |
| 52 | +// expected-error@-1 {{enum name can only start with a letter or underscore, not a number}} |
| 53 | +enum 18enum {} |
| 54 | +// expected-error@-1 {{enum name can only start with a letter or underscore, not a number}} |
| 55 | +// expected-error@-2 {{expected a digit in floating point exponent}} |
| 56 | + |
| 57 | +class 19 { |
| 58 | + // expected-error@-1 {{class name can only start with a letter or underscore, not a number}} |
| 59 | + func 20() {} |
| 60 | + // expected-error@-1 {{function name can only start with a letter or underscore, not a number}} |
| 61 | +} |
| 62 | +class 21.0 { |
| 63 | + // expected-error@-1 {{class name can only start with a letter or underscore, not a number}} |
| 64 | + func 22.0() {} |
| 65 | + // expected-error@-1 {{function name can only start with a letter or underscore, not a number}} |
| 66 | +} |
| 67 | + |
| 68 | +class 23class { |
| 69 | + // expected-error@-1 {{class name can only start with a letter or underscore, not a number}} |
| 70 | + // expected-error@-2 {{expected a digit after integer literal prefix}} |
| 71 | + func 24method() {} |
| 72 | + // expected-error@-1 {{function name can only start with a letter or underscore, not a number}} |
| 73 | + // expected-error@-2 {{expected a digit after integer literal prefix}} |
| 74 | +} |
0 commit comments