D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7457 - nested pure functions cannot access mutable context
Summary: nested pure functions cannot access mutable context
Status: RESOLVED DUPLICATE of issue 9148
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2012-02-07 10:53 UTC by timon.gehr
Modified: 2015-03-03 03:54 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description timon.gehr 2012-02-07 10:53:41 UTC
I think the following behavior of DMD is not mirrored in the documentation.

void main(){
    int x;
    void foo()pure{x=2;} // error
}

I think the spec is right, making this an error is problematic:

int bar(int delegate()pure dg)pure{return dg();}

int foo(int x)pure{
    return bar({return x+1;});// error
}

struct Delegate{
    int function(int*)pure fun;
    int* context;
    int call()pure{return fun(context);}
}

int bar2(Delegate dg)pure{return dg.call();}

int foo2(int x)pure{
    return bar2(Delegate(function(int* ptr){return *ptr+1;}, &x)); // fine      
}
Comment 1 Kenji Hara 2015-03-03 03:54:06 UTC
This is a dup of issue 9148, so it will be properly fixed in 2.067.

*** This issue has been marked as a duplicate of issue 9148 ***