[Issue 14962] New: [REG2.068] compiler inference of attributes for nested map seems broken
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Aug 25 11:03:09 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=14962
Issue ID: 14962
Summary: [REG2.068] compiler inference of attributes for nested
map seems broken
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: rejects-valid
Severity: regression
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: schveiguy at yahoo.com
Not sure if these are related, but they seem similar:
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() {
}
testfoo.d(12): Error: pure function
'testfoo.Foo.bar.__lambda1!int.__lambda1.__lambda2' cannot call impure function
'testfoo.Foo.baz'
/Users/steves/git/dmd2/osx/bin/../../src/phobos/std/algorithm/iteration.d(459):
instantiated from here: MapResult!(__lambda2, int[])
testfoo.d(12): instantiated from here: map!(int[])
/Users/steves/git/dmd2/osx/bin/../../src/phobos/std/algorithm/iteration.d(549):
instantiated from here: __lambda1!int
/Users/steves/git/dmd2/osx/bin/../../src/phobos/std/algorithm/iteration.d(459):
instantiated from here: MapResult!(__lambda1, int[])
testfoo.d(11): instantiated from here: map!(int[])
Another case:
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
}
}
testfoo.d(8): Error: need 'this' for 'baz' of type 'int()'
/Users/steves/git/dmd2/osx/bin/../../src/phobos/std/algorithm/iteration.d(459):
instantiated from here: MapResult!(__lambda2, int[])
testfoo.d(8): instantiated from here: map!(int[])
/Users/steves/git/dmd2/osx/bin/../../src/phobos/std/algorithm/iteration.d(549):
instantiated from here: __lambda2!int
/Users/steves/git/dmd2/osx/bin/../../src/phobos/std/algorithm/iteration.d(459):
instantiated from here: MapResult!(__lambda2, int[])
testfoo.d(8): instantiated from here: map!(int[])
I'm going to file this as a dmd issue, because it seems like it's a case of
attribute inference for the lambdas, not an issue with map.
--
More information about the Digitalmars-d-bugs
mailing list