Skip to content

Commit 44b1270

Browse files
authored
Merge pull request #19208 from nkcsgexi/fix-parse-infinite
Parser: Ignore and recover marked parse position during on-demand member parsing.
2 parents 24b61b3 + c4db694 commit 44b1270

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ void PersistentParserState::parseMembers(IterableDeclContext *IDC) {
185185
return;
186186
SourceFile &SF = *IDC->getDecl()->getDeclContext()->getParentSourceFile();
187187
unsigned BufferID = *SF.getBufferID();
188+
// MarkedPos is not useful for delayed parsing because we know where we should
189+
// jump the parser to. However, we should recover the MarkedPos here in case
190+
// the PersistentParserState will be used to continuously parse the rest of
191+
// the file linearly.
192+
llvm::SaveAndRestore<ParserPosition> Pos(MarkedPos, ParserPosition());
188193
Parser TheParser(BufferID, SF, nullptr, this);
189194
// Disable libSyntax creation in the delayed parsing.
190195
TheParser.SyntaxContext->disable();

test/Parse/delayed_extension.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %target-typecheck-verify-swift -swift-version 4
2+
3+
extension X { } // expected-error {{use of undeclared type 'X'}}
4+
_ = 1
5+
f() // expected-error {{use of unresolved identifier 'f'}}

0 commit comments

Comments
 (0)