www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - dmd 2.068 deducing purity

reply "Jack Applegame" <japplegame gmail.com> writes:
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'
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.
Aug 25 2015
parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
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
Aug 25 2015
parent reply "Jack Applegame" <japplegame gmail.com> writes:
On Tuesday, 25 August 2015 at 14:05:17 UTC, Steven Schveighoffer 
wrote:
 Can you post an example?
import std.range; import std.algorithm; class Foo { int baz() { return 1;} void bar() { auto s = [1].map!(i => baz()); // compiles auto r = [1].map!(i => [1].map!(j => baz())); // Error: need 'this' for 'baz' of type 'int()' } }
Aug 25 2015
parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
On 8/25/15 1:05 PM, Jack Applegame wrote:
 On Tuesday, 25 August 2015 at 14:05:17 UTC, Steven Schveighoffer wrote:
 Can you post an example?
import std.range; import std.algorithm; class Foo { int baz() { return 1;} void bar() { auto s = [1].map!(i => baz()); // compiles auto r = [1].map!(i => [1].map!(j => baz())); // Error: need 'this' for 'baz' of type 'int()' } }
https://issues.dlang.org/show_bug.cgi?id=14962 -Steve
Aug 25 2015
parent "Jack Applegame" <japplegame gmail.com> writes:
On Tuesday, 25 August 2015 at 18:03:21 UTC, Steven Schveighoffer 
wrote:
 https://issues.dlang.org/show_bug.cgi?id=14962

 -Steve
Thanks.
Aug 25 2015