Bug 17659 – `pure` causes function to be inferred as a delegate

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-07-17T16:47:53Z
Last change time
2024-12-13T18:53:26Z
Assigned to
No Owner
Creator
Tomer Filiba (weka)
Moved to GitHub: dmd#19284 →

Comments

Comment #0 by tomer — 2017-07-17T16:47:53Z
Consider the following void indirectCall(T)(T fn) { pragma(msg, T); } __gshared int x; void f() { indirectCall({x++;}); // void function() nothrow @nogc @system } void g() pure { indirectCall({x++;}); // pure delegate 'dtest.g.__lambda1' cannot access mutable static data 'x' } please ignore the mutable state issue -- the issue here that `{x++}` is treated as a function
Comment #1 by schveiguy — 2017-07-17T17:44:24Z
I'll add a note that it certainly is possible for a function to be inferred: void foo() pure { indirectCall(function() {x++;}); // void function() nothrow @nogc @system } The compiler should be able to do so.
Comment #2 by robert.schadek — 2024-12-13T18:53:26Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19284 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB