Syntax error at the end of a line prints the next line
If a syntax error happens at the end of a line i.e. the error position is the new line character, then the next line is included in the error message. Is this the intended behavior?
Note this example needs change from #3457.
No final newline
> cat /tmp/bug.fz
(#%
> FUZION_DISABLE_ANSI_ESCAPES=true fz /tmp/bug.fz
/tmp/bug.fz:1:3: error 1: Syntax error: expected term (lbrace, lparen, lcrochet, fun, string, integer, old, match, or name), found end-of-file
(#
--^
While parsing: term, parse stack: term, opTail, opExpr, operatorExpr, klammer, bracketTerm, term, opTail, opExpr, operatorExpr, expr, exprs, block, unit
one error.
With final newline
> cat /tmp/bug.fz
(#
> FUZION_DISABLE_ANSI_ESCAPES=true fz /tmp/bug.fz
/tmp/bug.fz:2:1: error 1: Syntax error: expected term (lbrace, lparen, lcrochet, fun, string, integer, old, match, or name), found end-of-file
^
While parsing: term, parse stack: term, opTail, opExpr, operatorExpr, klammer, bracketTerm, term, opTail, opExpr, operatorExpr, expr, exprs, block, unit
one error.
The relevant code is in showInSource() in SourcePosition.java
Your examples only show errors at the end of a file, which is a more special case than end of a line.
The question is, what is less confusing. In your example, we could report the error at the end of the file, or at #. But then # is a comment and there is nothing wrong with this comment, the problem is there is nothing coming after the comment, so reporting at the position of # is IMHO not a good alternative.
But if you have better ideas, in particular where 'real' code or typical errors lead to error messages that are confusing, please suggest improvements.