Bug 12434 – std.algorithm.sum of immutable array too

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2014-03-21T12:00:00Z
Last change time
2014-04-07T07:44:01Z
Keywords
rejects-valid
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2014-03-21T12:00:30Z
void main() { import std.algorithm: sum, map; auto a1 = [10, 20]; auto t1 = sum(a1); // OK immutable a2 = [10, 20]; auto t2 = sum(a2); // Error auto t3 = a2.map!(x => x).sum; // Error } dmd 2.066alpha: ...\dmd2\src\phobos\std\algorithm.d(1087,15): Error: template std.algorithm.sum cannot deduce function from argument types !()(immutable(int)[], immutable(int)), candidates are: ...\dmd2\src\phobos\std\algorithm.d(1079,6): std.algorithm.sum(R)(R r) if (isInputRange!R && !isInfinite!R && is(typeof(r.front + r.front))) ...\dmd2\src\phobos\std\algorithm.d(1090,6): std.algorithm.sum(R, E)(R r, E seed) if (isInputRange!R && !isInfinite!R && is(typeof(seed = seed + r.front))) test.d(6,18): Error: template instance std.algorithm.sum!(immutable(int)[]) error instantiating ...\dmd2\src\phobos\std\algorithm.d(1087,15): Error: template std.algorithm.sum cannot deduce function from argument types !()(MapResult!(__lambda1, immutable(int)[]), immutable(int)), candidates are: ...\dmd2\src\phobos\std\algorithm.d(1079,6): std.algorithm.sum(R)(R r) if (isInputRange!R && !isInfinite!R && is(typeof(r.front + r.front))) ...\dmd2\src\phobos\std\algorithm.d(1090,6): std.algorithm.sum(R, E)(R r, E seed) if (isInputRange!R && !isInfinite!R && is(typeof(seed = seed + r.front))) test.d(7,30): Error: template instance std.algorithm.sum!(MapResult!(__lambda1, immutable(int)[])) error instantiating
Comment #1 by monarchdodra — 2014-03-22T14:31:25Z
I'll look into this. Thanks.
Comment #2 by monarchdodra — 2014-04-06T13:17:38Z
(In reply to comment #1) > I'll look into this. Thanks. Trivial. https://github.com/D-Programming-Language/phobos/pull/2071
Comment #3 by github-bugzilla — 2014-04-07T07:43:45Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/6123ca33713ddd0dfcded8a46bcbef5c3e8e8a50 Fix Issue 12434 - std.algorithm.sum of immutable array too https://d.puremagic.com/issues/show_bug.cgi?id=12434 Simply uses the inference's `Unqual` type as a seed, rather than the straight up result. Also add some unittesting while at it. https://github.com/D-Programming-Language/phobos/commit/a3269b7591c21f0617ab687051a684766304c479 Merge pull request #2071 from monarchdodra/12434 Fix Issue 12434 - std.algorithm.sum of immutable array too