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
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/a552d6552d44de9284f03815ecfb32585f0186ac Fix Issue 17899 - Cannot initialise contextless delegate at compile time Also revert test case for 13259 - there is no reason that initialised module scope delegates should be illegal. https://github.com/dlang/dmd/commit/8476f8bb4e59e92ed8b01bcd7513066aae172139 Merge pull request #7704 from thewilsonator/patch-2 Fix Issue 17899: Allow delegate initialisation at module scope