First D project, problem with error messages

WebFreak001 d.forum at webfreak.org
Thu Feb 9 21:32:03 UTC 2023


On Thursday, 9 February 2023 at 19:37:44 UTC, Daniel wrote:
> [...]

Thanks for showing the weird error that would be on module.

The reason: libdparse (the D parser code-d / serve-d and all the 
other tools underlying it use) parses the code and the `''` is 
invalid according to D grammar, because inside `'x'` you always 
need to have exactly one character. This is emitted as invalid 
token directly at the lexing stage, the parser doesn't even know 
what it originally said in the code.

However this error token didn't include location information, so 
it defaulted to 0 location.

Now the parser emitted an error at the token location of the 
error token, because it expected a primary expression, but didn't 
get any valid token for one.

The emitted error is now processed in code-d, it thinks the byte 
offset is 0 (is a valid offset), doesn't know a length, so it 
guesses by picking the keyword that's at location 0.

I'm opening a PR to fix the location so at least this shouldn't 
be confusing anymore.


More information about the Digitalmars-d mailing list