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.
Two cases have different root issues, but had been introduce at once by: https://github.com/D-Programming-Language/dmd/pull/4464
(In reply to Steven Schveighoffer from comment #0) > 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 > } > } [snip] I separated the second case into issue 14973.
The behavior comes from issue 14781. So I also changed it to a regression. https://github.com/D-Programming-Language/dmd/pull/4970
Commits pushed to stable at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/0c9f5a272bf47e1ad81d2a8a4c56adfd3461fde7 fix Issue 14962 - compiler inference of attributes for nested map seems broken It has been revealed since the commit/PR: f22d9dbb42b6a32d5b4c7c9f3db45e07c9f8aaf6 https://github.com/D-Programming-Language/dmd/pull/4464 By the fix, some attribute inference order bug for template functions had been fixed - when foo() calls bar!(), and bar!() calls baz!(), the bar!() attribute should be inferred after the attrs of baz!() determined. And then, compiler infers the purity of nested two lambdas in the 14962 test case, and the case has been rejected by the 14781 behavior. https://github.com/D-Programming-Language/dmd/commit/b30556bf2ce1b4e49fdba51ea759725c2fc6e48f Merge pull request #4970 from 9rnsr/fix14781 [REG2.067/2.068] Issue 14781 & 14962 - fix problematic purity inference introduced in #3626
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/0c9f5a272bf47e1ad81d2a8a4c56adfd3461fde7 fix Issue 14962 - compiler inference of attributes for nested map seems broken https://github.com/D-Programming-Language/dmd/commit/b30556bf2ce1b4e49fdba51ea759725c2fc6e48f Merge pull request #4970 from 9rnsr/fix14781