Bug 7010 – Purity of map and filter

Status
RESOLVED
Resolution
WORKSFORME
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2011-11-25T16:39:00Z
Last change time
2013-07-09T09:01:21Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2011-11-25T16:39:07Z
There are some important cases where the purity inference of functions/delegates is not working well enough (DMD 2.057head): import std.algorithm: map, filter; int foo(immutable int x) pure nothrow { return 1; } void main() pure { immutable data = [1, 2, 3]; auto m1 = map!((x){ return 1; })(data); // OK auto m2 = map!((int x){ return 1; })(data); // OK auto m3 = map!q{ 1 }(data); // error, map is not pure auto m4 = map!foo(data); // error, map is not pure //------------ auto f1 = filter!((x){ return 1; })(data); // OK auto f2 = filter!((int x){ return 1; })(data); // OK auto f3 = filter!q{ 1 }(data); // error, filter is not pure auto f4 = filter!foo(data); // error, filter is not pure }
Comment #1 by k.hara.pg — 2011-11-25T22:39:24Z
The instantiation of map function given a delegate literal should not be inferred as pure, it is compiler bug. I've separated the issue into bug 7017. Then this issue is now purely Phobos enhancement.
Comment #2 by hsteoh — 2013-07-09T09:01:21Z
This appears to have been fixed in git HEAD.