D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5096 - More readable unpaired brace error
Summary: More readable unpaired brace error
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords: diagnostic, pull
Depends on:
Blocks:
 
Reported: 2010-10-21 15:16 UTC by bearophile_hugs
Modified: 2022-01-20 12:11 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2010-10-21 15:16:28 UTC
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 Adam D. Ruppe 2020-02-15 03:40:57 UTC
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 Adam D. Ruppe 2022-01-18 21:28:15 UTC
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 Dlang Bot 2022-01-20 04:05:00 UTC
@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 Dlang Bot 2022-01-20 12:11:56 UTC
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