Skip to content

Commit e594e1f

Browse files
authored
Merge pull request #3461 from ruby/fix-infinite-loop
Fix infinite loop in error recovery
2 parents 826b6b2 + a32e268 commit e594e1f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/prism.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13949,6 +13949,15 @@ parse_statements(pm_parser_t *parser, pm_context_t context, uint16_t depth) {
1394913949
if (PM_NODE_TYPE_P(node, PM_MISSING_NODE)) {
1395013950
parser_lex(parser);
1395113951

13952+
// If we are at the end of the file, then we need to stop parsing
13953+
// the statements entirely at this point. Mark the parser as
13954+
// recovering, as we know that EOF closes the top-level context, and
13955+
// then break out of the loop.
13956+
if (match1(parser, PM_TOKEN_EOF)) {
13957+
parser->recovering = true;
13958+
break;
13959+
}
13960+
1395213961
while (accept2(parser, PM_TOKEN_NEWLINE, PM_TOKEN_SEMICOLON));
1395313962
if (context_terminator(context, &parser->current)) break;
1395413963
} else if (!accept2(parser, PM_TOKEN_NEWLINE, PM_TOKEN_EOF)) {
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
x.each { x end
22
^~~ unexpected 'end', expecting end-of-input
33
^~~ unexpected 'end', ignoring it
4-
^ unexpected end-of-input, assuming it is closing the parent top level context
54
^ expected a block beginning with `{` to end with `}`
65

0 commit comments

Comments
 (0)