Skip to content

Commit 1f117b4

Browse files
committed
[parser] Make sure the isInputIncomplete() function works as expected for multi-line strings
1 parent 82be1a5 commit 1f117b4

File tree

6 files changed

+25
-0
lines changed

6 files changed

+25
-0
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,6 +1765,10 @@ ParserResult<Expr> Parser::parseExprPrimary(Diag<> ID, bool isExprBasic) {
17651765
// Eat an invalid token in an expression context. Error tokens are diagnosed
17661766
// by the lexer, so there is no reason to emit another diagnostic.
17671767
case tok::unknown:
1768+
if (Tok.getText().startswith("\"\"\"")) {
1769+
// This was due to unterminated multi-line string.
1770+
IsInputIncomplete = true;
1771+
}
17681772
consumeToken(tok::unknown);
17691773
return nullptr;
17701774

lib/Parse/ParseStmt.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ ParserStatus Parser::parseBraceItems(SmallVectorImpl<ASTNode> &Entries,
318318
// Eat invalid tokens instead of allowing them to produce downstream errors.
319319
if (Tok.is(tok::unknown)) {
320320
SyntaxParsingContext ErrContext(SyntaxContext, SyntaxContextKind::Stmt);
321+
if (Tok.getText().startswith("\"\"\"")) {
322+
// This was due to unterminated multi-line string.
323+
IsInputIncomplete = true;
324+
}
321325
consumeToken();
322326
continue;
323327
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""
2+
some
3+
multiline
4+
string
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
a +
2+
"""
3+
some
4+
multiline
5+
string
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""
2+
some
3+
multiline
4+
string
5+
\(

test/IDE/test-input-complete/test_input.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
// RUN: %swift-ide-test -test-input-complete -source-filename %S/Inputs/type_incomplete3.swift | %FileCheck %s -check-prefix=INCOMPLETE
3232
// RUN: %swift-ide-test -test-input-complete -source-filename %S/Inputs/type_incomplete4.swift | %FileCheck %s -check-prefix=INCOMPLETE
3333
// RUN: %swift-ide-test -test-input-complete -source-filename %S/Inputs/invalid_interpolation1.swift | %FileCheck %s -check-prefix=COMPLETE
34+
// RUN: %swift-ide-test -test-input-complete -source-filename %S/Inputs/multi_line_string1.swift | %FileCheck %s -check-prefix=INCOMPLETE
35+
// RUN: %swift-ide-test -test-input-complete -source-filename %S/Inputs/multi_line_string2.swift | %FileCheck %s -check-prefix=INCOMPLETE
36+
// RUN: %swift-ide-test -test-input-complete -source-filename %S/Inputs/multi_line_string3.swift | %FileCheck %s -check-prefix=INCOMPLETE
3437

3538
// INCOMPLETE: IS_INCOMPLETE
3639
// COMPLETE: IS_COMPLETE

0 commit comments

Comments
 (0)