Skip to content

Commit cbb790f

Browse files
committed
Proposal: Allow Single Dollar Sign as Valid Identified
1 parent b01ee4d commit cbb790f

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Allow Single Dollar Sign as Valid Identified
2+
3+
* Proposal: [SE-0000]()
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 the
11+
identifier `$` is used by itself. Swift should continue supporting
12+
use of `$` as an identifier but when used with non-numeric name
13+
consider it an error.
14+
15+
## Motivation
16+
17+
Currently a lot of projects depend on the following library
18+
[Dollar](https://github.com/ankurp/Dollar) which uses `$` as
19+
a namespace since it was valid since when Swift was released.
20+
Now the core team is deciding to remove it as a valid character
21+
according to this bug ticket [SR-1661](https://bugs.swift.org/browse/SR-1661)
22+
23+
The problem is that when used with a non-numeric name (e.g. $a),
24+
the compiler raises the correct error:
25+
26+
```swift
27+
ERROR at line 1, col 5: expected numeric value following '$'
28+
var $a = 5
29+
```
30+
31+
This may seem like inconsistent behavior to some causing the
32+
removing of `$` as a valid identifier in the language. Also `$`
33+
may be reserved for debugging tools in the future.
34+
35+
## Proposed solution
36+
37+
Allow `$` to be used a valid identifier and reserve `$$`
38+
(double dollar sign) for namespacing debugger tools in the
39+
future when they are introduced.
40+
41+
## Impact on existing code
42+
43+
This functionality is keeping the existing sytax in place so there
44+
will be no impact of existing code. But if the core team decides to
45+
remove the `$` as a valid identifier then it will impact a lot of
46+
developers code as it is being used indirectly by importing
47+
[Dollar](https://github.com/ankurp/Dollar) library.
48+
49+
## Alternatives considered
50+
51+
The primarily alternative here is to do nothing by closing this
52+
ticket [SR-1661](https://bugs.swift.org/browse/SR-1661)

0 commit comments

Comments
 (0)