Skip to content

parser: report errors inside argument lists at their position - #84

Merged
rameel merged 1 commit into
mainfrom
parser/report-errors-inside-argument-lists
Nov 24, 2026
Merged

rameel merged 1 commit into
mainfrom
parser/report-errors-inside-argument-lists

Conversation

@rameel

@rameel rameel commented Nov 24, 2026

Copy link
Copy Markdown
Owner

When an argument of a call or an indexer was broken, the error pointed at the comma before it or at the start of the list instead of where an expression is missing:

Expression Before After
"test".ToString(1,) (1:18) Expected ')' (1:19) Expected [!+\-~], …
Math.Max(1, (2 + )) (1:11) Expected ')' (1:18) Expected [!+\-~], …
"test"[(] (1:8) Expected expression (1:9) Expected [!+\-~], …

The argument lists were labeled with As, which discards the diagnostics from inside the list. This PR removes both labels, so the position matches the C# compiler. The message now lists the tokens that can start an expression, as for 1 +. This also applies to an empty indexer, as in "test"[], which has reported Expected expression since #83.

The arguments of a call and an indexer were labeled with As, which
discards the diagnostics from inside the labeled parser. A list stops
before a broken argument, so the error pointed at the comma before it
or at the start of the list rather than where an expression is missing:

    "test".ToString(1,)    (1:18) Expected ')'
    Math.Max(1, (2 + ))    (1:11) Expected ')'
    "test"[(]              (1:8) Expected expression

Remove both labels, so the error points where the expression is
missing, as in C#, and lists the tokens that can start an expression,
as for 1 +. An empty indexer, as in "test"[], gets the same list
instead of "Expected expression", and an unfinished list, as in
"test"[0, lists the operators, ',' and ']', as 1 + (2 * 3 does.
@rameel
rameel merged commit 48b7d36 into main Nov 24, 2026
1 check passed
@rameel
rameel deleted the parser/report-errors-inside-argument-lists branch November 24, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant