Bug 22691 – [diagnostic] mismatched braces still painful

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-01-20T14:18:26Z
Last change time
2024-12-13T19:20:28Z
Keywords
diagnostic
Assigned to
No Owner
Creator
Adam D. Ruppe
Moved to GitHub: dmd#20040 →

Comments

Comment #0 by destructionator — 2022-01-20T14:18:26Z
Consider: ``` class A { void foo() { int b; void nested() { if(a) { } } } b += 5; } void bar() { } } ``` error.d(10): Error: no identifier for declarator `b` error.d(10): Error: declaration expected, not `+=` error.d(16): Error: unrecognized declaration The actual problem is on line 7. The first error issued is on line 10. In real world code, there can be much, much, much more separation between the two. Even if you recognize this from experience as a brace paste error and put it through an auto formatter, you're still left eyeballing up for something that looks out of place. I'd recommend making the compiler remember the indentation level of an open brace. If it sees a closing brace on a different level, make a note of that. Don't need issue an error/warning yet, the compiler need not nag about style, just remember it. Then on the next error it actually does see, throw out the mismatched close as a supplemental hint as a likely root cause to investigate. So here, it'd be like error.d(10): Error: no identifier for declarator `b` hint: closing brace on line 7 appears mismatched
Comment #1 by robert.schadek — 2024-12-13T19:20:28Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20040 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB