Skip to content

Commit

Permalink
scanner: do not emit layout_empty during error recovery
Browse files Browse the repository at this point in the history
This token is only valid after a block, and it is impossible to see errors
here (since this node corresponds to literally nothing).

Don't emit this during error recovery to prevent strange interpretations.
  • Loading branch information
alaviss committed Sep 23, 2023
1 parent 5676fb9 commit a8bd63a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
25 changes: 25 additions & 0 deletions corpus/errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
================================================================================
Error within variant object declaration
================================================================================

type
E = object
case foo
of bar

--------------------------------------------------------------------------------

(source_file
(type_section
(type_declaration
(type_symbol_declaration
(identifier))
(object_declaration
(field_declaration_list
(variant_declaration
(variant_discriminator_declaration
(symbol_declaration_list
(symbol_declaration
(identifier)))))
(ERROR
(identifier)))))))
6 changes: 5 additions & 1 deletion src/scanner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,11 @@ bool lex_indent(Context& ctx)
return ctx.finish(TokenType::LayoutStart);
}

if (ctx.valid(TokenType::LayoutEmpty) &&
// LayoutEmpty has to be explicitly requested, and errors generally
// don't happen within the contexts it would be requested.
//
// Don't emit them on errors to prevent mangling error recovery.
if (!ctx.error() && ctx.valid(TokenType::LayoutEmpty) &&
ctx.state().test_flag(Flag::AfterNewline) &&
(current_layout >= line_indent || ctx.eof())) {
ctx.mark_end();
Expand Down

0 comments on commit a8bd63a

Please sign in to comment.