Skip to content

Commit 4536e69

Browse files
committed
[Lexer] Don't emit diagnostics in skipToEndOfInterpolatedExpression()
Removed Diags parameter from it. Skipped bytes are revisited by main lexer function anyway. So emitting diagnostics in it causes duplicated errors.
1 parent c9c6963 commit 4536e69

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

lib/Parse/Lexer.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,6 @@ unsigned Lexer::lexCharacter(const char *&CurPtr, char StopQuote,
14141414
/// outstanding delimiters as it scans the string.
14151415
static const char *skipToEndOfInterpolatedExpression(const char *CurPtr,
14161416
const char *EndPtr,
1417-
DiagnosticEngine *Diags,
14181417
bool IsMultilineString) {
14191418
SmallVector<char, 4> OpenDelimiters;
14201419
SmallVector<bool, 4> AllowNewline;
@@ -1452,7 +1451,7 @@ static const char *skipToEndOfInterpolatedExpression(const char *CurPtr,
14521451

14531452
case '#':
14541453
if (inStringLiteral() ||
1455-
!(CustomDelimiterLen = advanceIfCustomDelimiter(CurPtr, Diags)))
1454+
!(CustomDelimiterLen = advanceIfCustomDelimiter(CurPtr, nullptr)))
14561455
continue;
14571456
assert(CurPtr[-1] == '"' &&
14581457
"advanceIfCustomDelimiter() must stop at after the quote");
@@ -1463,7 +1462,7 @@ static const char *skipToEndOfInterpolatedExpression(const char *CurPtr,
14631462
if (!inStringLiteral()) {
14641463
// Open string literal.
14651464
OpenDelimiters.push_back(CurPtr[-1]);
1466-
AllowNewline.push_back(advanceIfMultilineDelimiter(CurPtr, Diags));
1465+
AllowNewline.push_back(advanceIfMultilineDelimiter(CurPtr, nullptr));
14671466
CustomDelimiter.push_back(CustomDelimiterLen);
14681467
continue;
14691468
}
@@ -1475,11 +1474,11 @@ static const char *skipToEndOfInterpolatedExpression(const char *CurPtr,
14751474
continue;
14761475

14771476
// Multi-line string can only be closed by '"""'.
1478-
if (AllowNewline.back() && !advanceIfMultilineDelimiter(CurPtr, Diags))
1477+
if (AllowNewline.back() && !advanceIfMultilineDelimiter(CurPtr, nullptr))
14791478
continue;
14801479

14811480
// Check whether we have equivalent number of '#'s.
1482-
if (!delimiterMatches(CustomDelimiter.back(), CurPtr, Diags, true))
1481+
if (!delimiterMatches(CustomDelimiter.back(), CurPtr, nullptr, true))
14831482
continue;
14841483

14851484
// Close string literal.
@@ -1492,7 +1491,7 @@ static const char *skipToEndOfInterpolatedExpression(const char *CurPtr,
14921491
// We ignore invalid escape sequence here. They should be diagnosed in
14931492
// the real lexer functions.
14941493
if (inStringLiteral() &&
1495-
delimiterMatches(CustomDelimiter.back(), CurPtr, Diags)) {
1494+
delimiterMatches(CustomDelimiter.back(), CurPtr, nullptr)) {
14961495
switch (*CurPtr++) {
14971496
case '(':
14981497
// Entering a recursive interpolated expression
@@ -1757,10 +1756,9 @@ void Lexer::lexStringLiteral(unsigned CustomDelimiterLen) {
17571756
&& *TmpPtr == '(') {
17581757
// Consume tokens until we hit the corresponding ')'.
17591758
CurPtr = TmpPtr + 1;
1760-
const char *EndPtr =
1761-
skipToEndOfInterpolatedExpression(CurPtr, BufferEnd,
1762-
Diags, IsMultilineString);
1763-
1759+
const char *EndPtr = skipToEndOfInterpolatedExpression(CurPtr, BufferEnd,
1760+
IsMultilineString);
1761+
17641762
if (*EndPtr == ')') {
17651763
// Successfully scanned the body of the expression literal.
17661764
CurPtr = EndPtr+1;
@@ -2231,9 +2229,8 @@ void Lexer::getStringLiteralSegments(
22312229
IsFirstSegment = false;
22322230

22332231
// Find the closing ')'.
2234-
const char *End = skipToEndOfInterpolatedExpression(BytesPtr,
2235-
Str.getText().end(),
2236-
Diags, MultilineString);
2232+
const char *End = skipToEndOfInterpolatedExpression(
2233+
BytesPtr, Str.getText().end(), MultilineString);
22372234
assert(*End == ')' && "invalid string literal interpolations should"
22382235
" not be returned as string literals");
22392236
++End;

test/Parse/raw_string_errors.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
// RUN: %target-typecheck-verify-swift
22

3-
#"\##("invalid")"#
3+
let _ = "foo\(#"bar"##)baz"
4+
// expected-error@-1{{too many '#' characters in closing delimiter}}
5+
// expected-error@-2{{expected ',' separator}}
6+
// expected-error@-3{{expected expression in list of expressions}}
7+
8+
let _ = #"\##("invalid")"#
49
// expected-error@-1{{too many '#' characters in delimited escape}}
510
// expected-error@-2{{invalid escape sequence in literal}}
611

7-
####"invalid"###
12+
let _ = ####"invalid"###
813
// expected-error@-1{{unterminated string literal}}
914
10-
###"invalid"####
15+
let _ = ###"invalid"####
1116
// expected-error@-1{{too many '#' characters in closing delimiter}}
1217
// expected-error@-2{{consecutive statements on a line must be separated by ';'}}
1318
// expected-error@-3{{expected expression}}
14-
// expected-warning@-4{{string literal is unused}}

0 commit comments

Comments
 (0)