diff --git a/lib/Parse/Lexer.cpp b/lib/Parse/Lexer.cpp index d0f77000461aa..eb8cd35e4f38b 100644 --- a/lib/Parse/Lexer.cpp +++ b/lib/Parse/Lexer.cpp @@ -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++ @@ -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); diff --git a/test/Parse/dollar_identifier.swift b/test/Parse/dollar_identifier.swift index 73d2594402e3b..f72adb39b9b08 100644 --- a/test/Parse/dollar_identifier.swift +++ b/test/Parse/dollar_identifier.swift @@ -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 '$'}} +}