[Issue 22691] New: [diagnostic] mismatched braces still painful
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jan 20 14:18:26 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=22691
Issue ID: 22691
Summary: [diagnostic] mismatched braces still painful
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: destructionator at gmail.com
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
--
More information about the Digitalmars-d-bugs
mailing list