dmd 2.068 deducing purity

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Aug 25 07:05:17 PDT 2015


On 8/25/15 9:59 AM, Jack Applegame wrote:
> Using lambdas in 2.068 becomes painful:
>
>> import std.algorithm;
>>
>> struct Foo {
>>     int baz(int v) {
>>         static int id;
>>         return v + id++;
>>     }
>>     void bar() {
>>         auto arr1 = [1, 2, 3];
>>         auto arr2 = [4, 5, 6];
>>         arr1.map!(i =>
>>             arr2.map!(j => baz(i + j))
>>         );
>>     }
>> }
>>
>> void main() {
>> }
>
>> Error: pure function 'bug.Foo.bar.__lambda1!int.__lambda1.__lambda2'
>> cannot call impure function 'bug.Foo.baz'

That seems like a bug, I see no pure in sight there, the compiler 
shouldn't infer pure if the inferred function is calling impure functions.

> Also after switching to dmd 2.068 I got many stupid errors in lambdas
> (defined inside class non-static functions):
>
>> Error: need 'this' for '...' of type '...'
>
> I have no idea how to fix it and had to go back to 2.067.

Can you post an example?

-Steve


More information about the Digitalmars-d-learn mailing list