Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/Parse/Lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ static bool isValidIdentifierContinuationCodePoint(uint32_t c) {
static bool isValidIdentifierStartCodePoint(uint32_t c) {
if (!isValidIdentifierContinuationCodePoint(c))
return false;
if (c < 0x80 && isDigit(c))
if (c < 0x80 && (isDigit(c) || c == '$'))
return false;

// N1518: Recommendations for extended identifier characters for C and C++
Expand Down Expand Up @@ -1385,6 +1385,14 @@ void Lexer::lexEscapedIdentifier() {
}
}

// Special case; allow '`$`'.
if (Quote[1] == '$' && Quote[2] == '`') {
CurPtr = Quote + 3;
formToken(tok::identifier, Quote);
NextToken.setEscapedIdentifier(true);
return;
}

// The backtick is punctuation.
CurPtr = IdentifierStart;
formToken(tok::backtick, Quote);
Expand Down
7 changes: 7 additions & 0 deletions test/Parse/dollar_identifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,10 @@ func escapedDollarFunc() {
func `$`(`$`: Int) {} // no error
`$`(`$`: 25) // no error
}

func escapedDollarAnd() {
// FIXME: Bad diagnostics.
`$0` = 1 // expected-error {{expected expression}}
`$$` = 2 // expected-error {{expected numeric value following '$'}}
`$abc` = 3 // expected-error {{expected numeric value following '$'}}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the Swift3 behavior. Diagnostics doesn't look nice.
We can improve this, but not for now.

}