D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7510 - implicit conversion to immutable fails for pure delegates and function pointers
Summary: implicit conversion to immutable fails for pure delegates and function pointers
Status: REOPENED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-15 10:41 UTC by timon.gehr
Modified: 2024-12-13 17:58 UTC (History)
1 user (show)

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-15 10:41:38 UTC
DMD 2.058:

void main(){
    auto foo()pure{return new int[100];}
    immutable int[] x = foo(); // ok
    immutable int[] y = {return new int[100];}(); // ng
    immutable int[] z = delegate{return new int[100];}(); // ng
}

The code should compile.
Comment 1 yebblies 2013-11-26 21:57:22 UTC
As delegates/nested functions, they are not strongly pure and can access mutable data in the enclosing function.  It works if they are made static.
Comment 2 timon.gehr 2013-11-27 08:14:30 UTC
(In reply to comment #1)
> As delegates/nested functions, they are not strongly pure and can access
> mutable data in the enclosing function.

No, they can't because they don't.

> It works if they are made static.

That implies that this request is _valid_, not the opposite. Function literals have attributes inferred. The first step for making this pass is to even allow the 'immutable' attribute on strongly pure delegate literals.

Note that the way purity is handled for delegate literals by DMD is wrong, since it has not been updated after the meaning of 'pure' was updated.
Comment 3 dlangBugzillaToGithub 2024-12-13 17:58:23 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18414

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB