Bug 5096 – More readable unpaired brace error

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-10-21T15:16:28Z
Last change time
2022-01-20T12:11:56Z
Keywords
diagnostic, pull
Assigned to
No Owner
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2010-10-21T15:16:28Z
This is a wrong D2 program: void foo(int x) in { assert(x > 0); } body { x++; } } void main() {} DMD 2.049 shows at compile-time: test.d(7): unrecognized declaration But that's not easy to understand. A simpler to understand error message may be something like: test.d(7): closing brace lacking a corresponding open brace. Good error messages may shave away wasted seconds during debug, and seconds add up.
Comment #1 by destructionator — 2020-02-15T03:40:57Z
Just wasted ~ 5 mins due to this. struct Foo { void foo() { if(1) assert(0); } } } enhance.d(7): Error: unrecognized declaration Of course in my real code it reported terminal.d(1681): Error: unrecognized declaration turns out on line 943, I wrote `void thing() { if() .... } } `. missing the opening { on the if Yes, 700 lines apart in the real thing. Perhaps you say this belongs in a linter but this could have been detected perhaps by seeing the close brace isn't on the same indent as its corresponding open line (not always true but can maybebe worth a warning anyway)
Comment #2 by destructionator — 2022-01-18T21:28:15Z
This struck me AGAIN last week. I copy/pasted some code to shuffle things into a nested function and brought in an extra }. The first error message issued was *hundreds of lines* past the actual error, then the remaining ones even further out.
Comment #3 by dlang-bot — 2022-01-20T04:05:00Z
@benjones created dlang/dmd pull request #13552 "fix issue 5096: bad unmatched closing brace messages" fixing this issue: - fix issue 5096: bad unmatched closing brace messages https://github.com/dlang/dmd/pull/13552
Comment #4 by dlang-bot — 2022-01-20T12:11:56Z
dlang/dmd pull request #13552 "fix issue 5096: bad unmatched closing brace messages" was merged into master: - 53bad75bf8d40bcf32551715df3a8a7e2eb764d8 by Ben Jones: fix issue 5096: bad unmatched closing brace messages https://github.com/dlang/dmd/pull/13552