Bug 14378 – Parse block statement followed by ';' as a function literal
Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-03-30T23:45:50Z
Last change time
2023-03-23T17:43:36Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
briancschott
Comments
Comment #0 by briancschott — 2015-03-30T23:45:50Z
Code:
```
import std.stdio;
void main()
{
{ writeln("test"); };
}
```
This program compiles and prints "test". The expected behavior is a compilation failure with a message like "Error: delegate has no effect in expression { writeln("test"); };"
Comment #1 by ketmar — 2015-03-31T03:53:46Z
i believe that delegates must have parameter declaration before body.
what we got here is block statement followed by empty statement (";"). so compiler can cry about the last if it wants, but not about delegate.
ahem. so it's a bug in specs, i believe, 'cause it's very hard to distinguish block statements from function literals with the current definition, and it's not intuitive at all.
thank you, i somehow missed that thing in specs. making semicolon the only difference is puzzling for programmer.
would you mind to open a topic in NG for this? i believe that in this case specs must be fixed, not compiler.
Comment #4 by yebblies — 2015-04-11T07:25:23Z
AFAIK this is intentional. If this context is ambiguous, it will be parsed as a block statement. You will probably want to make this a spec bug, but I'll leave that to you.
Comment #5 by nick — 2023-03-23T17:43:36Z
Marking as duplicate as the other issue is clearer about action needed.
*** This issue has been marked as a duplicate of issue 21619 ***