Skip to content

Commit 6d0c739

Browse files
committed
Parse: An empty escaped identifier is entirely whitespace
1 parent ff941bc commit 6d0c739

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

lib/Parse/Lexer.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -660,8 +660,8 @@ static bool advanceIfValidContinuationOfOperator(char const *&ptr,
660660

661661
/// Returns true if the given string is entirely whitespace (considering only
662662
/// those whitespace code points permitted in raw identifiers).
663-
static bool isEntirelyWhitespace(StringRef string) {
664-
if (string.empty()) return false;
663+
static bool isEscapedIdentifierEntirelyWhitespace(StringRef string) {
664+
if (string.empty()) return true;
665665
char const *p = string.data(), *end = string.end();
666666
if (!advanceIf(p, end, isPermittedRawIdentifierWhitespace))
667667
return false;
@@ -703,7 +703,7 @@ bool Lexer::isValidAsEscapedIdentifier(StringRef string) {
703703
;
704704
if (p != end)
705705
return false;
706-
return !isEntirelyWhitespace(string);
706+
return !isEscapedIdentifierEntirelyWhitespace(string);
707707
}
708708

709709
/// Determines if the given string is a valid operator identifier,
@@ -2315,7 +2315,8 @@ void Lexer::lexEscapedIdentifier() {
23152315
// If we have the terminating "`", it's an escaped/raw identifier, unless it
23162316
// contained only operator characters or was entirely whitespace.
23172317
StringRef IdStr(IdentifierStart, CurPtr - IdentifierStart);
2318-
if (*CurPtr == '`' && !isOperator(IdStr) && !isEntirelyWhitespace(IdStr)) {
2318+
if (*CurPtr == '`' && !isOperator(IdStr) &&
2319+
!isEscapedIdentifierEntirelyWhitespace(IdStr)) {
23192320
++CurPtr;
23202321
formEscapedIdentifierToken(Quote);
23212322
return;
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// {"signature":"swift::Lexer::formEscapedIdentifierToken(char const*)"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
``

0 commit comments

Comments
 (0)