Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
August 25, 2015 dmd 2.068 deducing purity | ||||
---|---|---|---|---|
| ||||
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. |
August 25, 2015 Re: dmd 2.068 deducing purity | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jack Applegame | 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 |
August 25, 2015 Re: dmd 2.068 deducing purity | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | 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()'
}
}
|
August 25, 2015 Re: dmd 2.068 deducing purity | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jack Applegame | 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 |
August 25, 2015 Re: dmd 2.068 deducing purity | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Tuesday, 25 August 2015 at 18:03:21 UTC, Steven Schveighoffer wrote:
>
>
> https://issues.dlang.org/show_bug.cgi?id=14962
>
> -Steve
Thanks.
|
Copyright © 1999-2021 by the D Language Foundation