Skip to content

Commit c4db694

Browse files
committed
Parser: Ignore and recover marked parse position during on-demand member parsing.
New construction of a parser instance will reset the marked parser position in PersistentParserState. We should recover the marked parser position during on-demand parsing in case the marked position will be later used to create another parser instance to continue parsing linearly.
1 parent 425221e commit c4db694

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)