[Issue 24047] compiler accepts unparseable code for unittests when -unittest is not provided

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Aug 8 18:42:43 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=24047

--- Comment #2 from Steven Schveighoffer <schveiguy at gmail.com> ---
> Why?

The grammar specifies "BlockStatement", not "GarbageWithSomeBraceMatching"

The result is surprising to say the least. I don't know what is saved by doing
an alternate grammar parsing, but I doubt it's worth it. This basically says
that the D compiler is not a valid parser of the D grammar unless the -unittest
switch is enabled.

A good test would be to parse (but not compile) std.datetime, which is full of
unittests, and compare the performance (memory and speed) and see if it's worth
it.

Would it be really bad to at least expect an opening brace as the next token?
That shouldn't be too expensive. I'm not sure how much parser state can be kept
without generating AST to validate the grammar, but it just feels wrong to have
invalid syntax pass the parser.

--


More information about the Digitalmars-d-bugs mailing list