|
1 |
| -// RUN: %target-parse-verify-swift |
| 1 | +// RUN: %target-parse-verify-swift -swift-version 4 |
2 | 2 |
|
3 |
| -// SR-1661: Dollar was accidentally allowed as an identifier and identifier head. |
| 3 | +// SR-1661: Dollar was accidentally allowed as an identifier in Swift 3. |
| 4 | +// SE-0144: Reject this behavior in the future. |
4 | 5 |
|
5 | 6 | func dollarVar() {
|
6 |
| - var $ : Int = 42 // expected-error {{expected numeric value following '$'}} expected-error {{expected pattern}} |
| 7 | + var $ : Int = 42 // expected-error {{'$' is not an identifier; use backticks to escape it}} {{7-8=`$`}} |
| 8 | + $ += 1 // expected-error {{'$' is not an identifier; use backticks to escape it}} {{3-4=`$`}} |
| 9 | + print($) // expected-error {{'$' is not an identifier; use backticks to escape it}} {{9-10=`$`}} |
7 | 10 | }
|
8 | 11 | func dollarLet() {
|
9 |
| - let $ = 42 // expected-error {{expected numeric value following '$'}} expected-error {{expected pattern}} |
| 12 | + let $ = 42 // expected-error {{'$' is not an identifier; use backticks to escape it}} {{7-8=`$`}} |
| 13 | + print($) // expected-error {{'$' is not an identifier; use backticks to escape it}} {{9-10=`$`}} |
10 | 14 | }
|
11 | 15 | func dollarClass() {
|
12 |
| - class $ {} // expected-error {{expected numeric value following '$'}} |
13 |
| - // expected-error@-1 {{expression resolves to an unused function}} |
14 |
| - // expected-error@-2 {{expected identifier in class declaration}} |
15 |
| - // expected-error@-3 {{braced block of statements is an unused closure}} |
| 16 | + class $ {} // expected-error {{'$' is not an identifier; use backticks to escape it}} {{9-10=`$`}} |
16 | 17 | }
|
17 | 18 | func dollarEnum() {
|
18 |
| - enum $ {} // expected-error {{expected numeric value following '$'}} |
19 |
| - // expected-error@-1 {{expected identifier in enum declaration}} |
20 |
| - // expected-error@-2 {{expression resolves to an unused function}} |
21 |
| - // expected-error@-3 {{braced block of statements is an unused closure}} |
| 19 | + enum $ {} // expected-error {{'$' is not an identifier; use backticks to escape it}} {{8-9=`$`}} |
22 | 20 | }
|
23 | 21 | func dollarStruct() {
|
24 |
| - struct $ {} // expected-error {{expected numeric value following '$'}} |
25 |
| - // expected-error@-1 {{expected identifier in struct declaration}} |
26 |
| - // expected-error@-2 {{braced block of statements is an unused closure}} |
27 |
| - // expected-error@-3 {{expression resolves to an unused function}} |
| 22 | + struct $ {} // expected-error {{'$' is not an identifier; use backticks to escape it}} {{10-11=`$`}} |
28 | 23 | }
|
29 | 24 |
|
| 25 | +func dollarFunc() { |
| 26 | + func $($ dollarParam: Int) {} |
| 27 | + // expected-error@-1 {{'$' is not an identifier; use backticks to escape it}} {{8-9=`$`}} |
| 28 | + // expected-error@-2 {{'$' is not an identifier; use backticks to escape it}} {{10-11=`$`}} |
| 29 | + $($: 24) |
| 30 | + // expected-error@-1 {{'$' is not an identifier; use backticks to escape it}} {{3-4=`$`}} |
| 31 | + // expected-error@-2 {{'$' is not an identifier; use backticks to escape it}} {{5-6=`$`}} |
| 32 | +} |
| 33 | + |
| 34 | +func escapedDollarVar() { |
| 35 | + var `$` : Int = 42 // no error |
| 36 | + `$` += 1 |
| 37 | + print(`$`) |
| 38 | +} |
| 39 | +func escapedDollarLet() { |
| 40 | + let `$` = 42 // no error |
| 41 | + print(`$`) |
| 42 | +} |
| 43 | +func escapedDollarClass() { |
| 44 | + class `$` {} // no error |
| 45 | +} |
| 46 | +func escapedDollarEnum() { |
| 47 | + enum `$` {} // no error |
| 48 | +} |
| 49 | +func escapedDollarStruct() { |
| 50 | + struct `$` {} // no error |
| 51 | +} |
| 52 | + |
| 53 | +func escapedDollarFunc() { |
| 54 | + func `$`(`$`: Int) {} // no error |
| 55 | + `$`(`$`: 25) // no error |
| 56 | +} |
0 commit comments