Skip to content

Error reporting differs between clox and jlox #1178

Open
@s7effeno

Description

@s7effeno

Why doesn't clox support non-synchronizing errors for its compiler? This alters error reporting quite a bit in some cases.
Take this input in exam:
if (1 = 1) { print 1; }

jlox parses the whole assignment, then reports [line 1] Error at '=': Invalid assignment target., then calls statement() to parse the then-branch and doesn't find any more errors.

clox does this:

  • consumes "if 1 =", reports [line 1] Error at '=': Invalid assignment target. and enables panic mode
  • expects a ')' but finds the second '1' so it triggers a silent error
  • tries to parse the then-branch as an expression statement starting with "1) ..."
  • consumes '1' but finds ')' instead of ';' so it triggers a silent error
  • starts synchronization
  • consumes up to "print" exluded
  • flawlessly parses "print 1;"
  • tries to parse the expression statement starting with '}'
  • reports [line 1] Error at '}': Expect expression.
  • tl;dr: skips to print... and signals unopened block

Is this design intended for simplicity? Am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions