|
| 1 | +# Allow Single Dollar Sign as Valid Identified |
| 2 | + |
| 3 | +* Proposal: [SE-NNNN](NNNN-allow-single-dollar-sign-as-valid-identifier) |
| 4 | +* Author: [Ankur Patel](https://github.com/ankurp) |
| 5 | +* Status: **Awaiting review** |
| 6 | +* Review manager: TBD |
| 7 | + |
| 8 | +## Introduction |
| 9 | + |
| 10 | +Currently, the compiler does not generate an error when `$` character is used |
| 11 | +as an identifier by itself. Swift should continue supporting use of `$` as a |
| 12 | +valid identifier in Swift 3 and later versions of Swift. |
| 13 | + |
| 14 | +## Motivation |
| 15 | + |
| 16 | +Currently a lot of projects depend on the following library |
| 17 | +[Dollar](https://github.com/ankurp/Dollar) which uses `$` as a namespace because |
| 18 | +it was a valid identifier since Swift was released. Now the core team is |
| 19 | +deciding to remove it as a valid character according to this bug ticket |
| 20 | +[SR-1661](https://bugs.swift.org/browse/SR-1661) |
| 21 | + |
| 22 | +The reason why the core team wishes to remove `$` as a valid identifier is |
| 23 | +to make the behavior consistent as `$` when suffixed with a valid identifier, |
| 24 | +(i.e. \$[a-zA-Z_....]), will raise an error: |
| 25 | + |
| 26 | +```swift |
| 27 | +ERROR at line 1, col 5: expected numeric value following '$' |
| 28 | +var $a = 5 |
| 29 | +``` |
| 30 | + |
| 31 | +Also `$` may be reserved for debugging tools in the future. |
| 32 | + |
| 33 | +## Proposed solution |
| 34 | + |
| 35 | +Allow `$` to be used a valid identifier and reserve `$$` (double dollar sign) |
| 36 | +for namespacing debugger tools in the future when they are introduced. |
| 37 | + |
| 38 | +## Impact on existing code |
| 39 | + |
| 40 | +This functionality is keeping the existing sytax in place so there will be no |
| 41 | +impact of existing code. But if the core team decides to remove the `$` as a |
| 42 | +valid identifier then it will impact a lot of developers code as it is being |
| 43 | +used indirectly by importing [Dollar](https://github.com/ankurp/Dollar) library. |
| 44 | + |
| 45 | +## Alternatives considered |
| 46 | + |
| 47 | +The primarily alternative here is to do nothing by closing this ticket |
| 48 | +[SR-1661](https://bugs.swift.org/browse/SR-1661) |
0 commit comments