File tree Expand file tree Collapse file tree 4 files changed +42
-8
lines changed Expand file tree Collapse file tree 4 files changed +42
-8
lines changed Original file line number Diff line number Diff line change @@ -805,7 +805,7 @@ void Lexer::lexOperatorIdentifier() {
805
805
return formToken (leftBound ? tok::oper_postfix : tok::oper_prefix, TokStart);
806
806
}
807
807
808
- // / lexDollarIdent - Match $[0-9a-zA-Z_$]*
808
+ // / lexDollarIdent - Match $[0-9a-zA-Z_$]+
809
809
void Lexer::lexDollarIdent () {
810
810
const char *tokStart = CurPtr-1 ;
811
811
assert (*tokStart == ' $' );
@@ -826,10 +826,15 @@ void Lexer::lexDollarIdent() {
826
826
}
827
827
}
828
828
829
- // It's always an error to see a standalone $, and we reserve
830
- // $nonNumeric for persistent bindings in the debugger.
831
- if (CurPtr == tokStart + 1 || !isAllDigits) {
832
- if (!isAllDigits && !LangOpts.EnableDollarIdentifiers )
829
+ // It's always an error to see a standalone $
830
+ if (CurPtr == tokStart + 1 ) {
831
+ diagnose (tokStart, diag::expected_dollar_numeric);
832
+ return formToken (tok::unknown, tokStart);
833
+ }
834
+
835
+ // We reserve $nonNumeric for persistent bindings in the debugger.
836
+ if (!isAllDigits) {
837
+ if (!LangOpts.EnableDollarIdentifiers )
833
838
diagnose (tokStart, diag::expected_dollar_numeric);
834
839
835
840
// Even if we diagnose, we go ahead and form an identifier token,
Original file line number Diff line number Diff line change 31
31
32
32
#if !_compiler_version("777.*.7")
33
33
// This shouldn't emit any diagnostics.
34
- $# % ^*&
34
+ % # ^*&
35
35
#endif
36
36
37
37
#if _compiler_version("700a.*.10") // expected-error {{version component contains non-numeric characters}}
Original file line number Diff line number Diff line change 31
31
32
32
#if !swift(>=1.0)
33
33
// This shouldn't emit any diagnostics.
34
- $# % ^*&
34
+ % # ^*&
35
35
#endif
36
36
37
37
#if swift(">=7.1") // expected-error {{unexpected platform condition argument: expected a unary comparison, such as '>=2.2'}}
@@ -62,7 +62,7 @@ protocol P {
62
62
63
63
// There should be no error here.
64
64
adsf asdf asdf
65
- $#% ^*&
65
+ % # ^*&
66
66
func foo( sdfsdfdsf adsf adsf asdf adsf adsf)
67
67
#endif
68
68
}
Original file line number Diff line number Diff line change
1
+ // RUN: %target-parse-verify-swift
2
+
3
+ // SR-1661: Dollar was accidentally allowed as an identifier and identifier head.
4
+
5
+ func dollarVar( ) {
6
+ var $ : Int = 42 // expected-error {{expected numeric value following '$'}} expected-error {{expected pattern}}
7
+ }
8
+ func dollarLet( ) {
9
+ let $ = 42 // expected-error {{expected numeric value following '$'}} expected-error {{expected pattern}}
10
+ }
11
+ 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
+ }
17
+ 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}}
22
+ }
23
+ 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}}
28
+ }
29
+
You can’t perform that action at this time.
0 commit comments