Skip to content

Commit af82619

Browse files
ankurplattner
authored andcommitted
Proposal: Allow Single Dollar Sign as Valid Identified (#354)
1 parent e2614ab commit af82619

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
* Review manager: TBD
6+
* Status: **Awaiting review**
7+
8+
## Introduction
9+
10+
Currently, the Swift compiler does not throw any errors when `$`
11+
character (U+0024) is used as an identifier by itself. For example:
12+
13+
```swift
14+
let $ = 10
15+
// OR
16+
let $ : (Int) -> (Int) = { $0 * $0 }
17+
// OR
18+
class $ {}
19+
```
20+
21+
Swift language should continue to support the use of `$` as a valid
22+
identifier in future versions of Swift (>= 3.1).
23+
24+
## Motivation
25+
26+
Currently a lot of projects depend on the following library
27+
[Dollar](https://github.com/ankurp/Dollar), which uses `$` character (U+0024)
28+
as a namespace because it was a valid identifier since Swift was released.
29+
The core team has decided to remove it as a valid character by merging this
30+
[Pull Request](https://github.com/apple/swift/pull/3901)
31+
32+
The reason behind the removal of `$` character as a valid identifier is
33+
to make the behavior consistent as `$` when suffixed with a valid identifier,
34+
(i.e. \$[a-zA-Z_....]), will raise an error:
35+
36+
```swift
37+
ERROR at line 1, col 5: expected numeric value following '$'
38+
var $a = 5
39+
```
40+
41+
Also they wish to reserve `$` for future debugging tools.
42+
43+
## Proposed solution
44+
45+
Allow `$` character (U+0024) to be used as a valid identifier without use of
46+
any tick marks `` `$` ``.
47+
48+
## Impact on existing code
49+
50+
This proposal will preserve existing syntax of allowing `$` to be used as a
51+
valid identifier by itself, so there will be no impact on existing code. But
52+
if `$` (U+0024) character is removed from being used as a valid identifier
53+
then it will impact a lot of developers who use the
54+
[Dollar](https://github.com/ankurp/Dollar) library.
55+
56+
## Alternatives considered
57+
58+
The primarily alternative here is to allow for the breaking change and use
59+
`` `$` `` as the identifier in the [Dollar](https://github.com/ankurp/Dollar)
60+
library.

0 commit comments

Comments
 (0)