www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12434] New: std.algorithm.sum of immutable array too

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12434

           Summary: std.algorithm.sum of immutable array too
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



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

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 21 2014
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12434


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra gmail.com



I'll look into this. Thanks.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 22 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12434





 I'll look into this. Thanks.
Trivial. https://github.com/D-Programming-Language/phobos/pull/2071 -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 06 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12434




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


Fix Issue 12434 - std.algorithm.sum of immutable array too

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 07 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12434


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrej.mitrovich gmail.com
         Resolution|                            |FIXED


-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 07 2014