Bug 17899 – Cannot initialise contextless delegate at compile time
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-10-15T01:16:26Z
Last change time
2018-01-23T17:38:57Z
Assigned to
No Owner
Creator
Nicholas Wilson
Comments
Comment #0 by iamthewilsonator — 2017-10-15T01:16:26Z
module foo;
void delegate() bar = (){};
complains about requiring a context for the initialisation that is unavailable at compile time.
The assignment to bar (and all delegates) at compile time has no context (can only refer to [thread local] globals by value) and so should compile with the context pointer = null.
This would remove the necessity for module constructors to do the assignment.
It would also solve https://github.com/libmir/dcompute/issues/32 where the module constructors fail to initialise the delegates properly, which is a separate issue that I haven't been able to pin down (not yet reported).
Comment #1 by razvan.nitu1305 — 2017-10-18T12:05:09Z
Running the example on git HEAD issues : "Error: non-constant nested delegate literal expression __lambda3" which is pretty cryptic.
Comment #2 by iamthewilsonator — 2018-01-12T04:49:05Z
Hmm, it seems this behaviour was added to fix #13259, but that should be legal, i.e. not an error.
Comment #3 by iamthewilsonator — 2018-01-12T04:50:36Z
(In reply to RazvanN from comment #1)
> Running the example on git HEAD issues : "Error: non-constant nested
> delegate literal expression __lambda3" which is pretty cryptic.
Hmm, it seems this behaviour was added to fix issue 13259, but that should be legal, i.e. not an error.
Comment #4 by github-bugzilla — 2018-01-23T17:38:56Z