Bug 12682 – Bad error messages with global assignment of mutable lambda value
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2014-04-30T09:16:46Z
Last change time
2023-02-17T13:06:34Z
Keywords
diagnostic
Assigned to
No Owner
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2014-04-30T09:16:46Z
int function(int) f2;
auto f1 = (int x) => x; // OK
f2 = (int x) => x; // Errors
void main() {
f2 = (int x) => x; // OK
}
DMD 2.066alpha gives:
test.d(3,9): Error: no identifier for declarator f2
test.d(3,9): Error: Declaration expected, not '='
Here I'd like D to give a single better error message, that explains the true problem.
Comment #1 by razvan.nitu1305 — 2022-08-22T15:34:31Z
The problem is that this code is violating the grammar. DMD expects a declaration but we have an expression, so it just errors out with a silly token error. I don't know if this can be properly fixed, since you have to actually parse ahead to see what you got there and if multiple errors occur, then it's hard to know where to restart parsing.