D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 12682 - Bad error messages with global assignment of mutable lambda value
Summary: Bad error messages with global assignment of mutable lambda value
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P3 normal
Assignee: No Owner
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2014-04-30 09:16 UTC by bearophile_hugs
Modified: 2023-02-17 13:06 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2014-04-30 09:16:46 UTC
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 RazvanN 2022-08-22 15:34:31 UTC
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.