www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8758] New: A problem with zip.map.reduce at compile time


           Summary: A problem with zip.map.reduce at compile time
           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

I am not sure if this is a bug or just a problem in my code:

import std.algorithm: map, reduce;
import std.range: zip;
struct S {}
alias bool function(S) F;
F foo(T)(T) {
    return p => true;
F bar(F r1, F r2) {
    return p => true;
F spam(S[] ps) {
    return zip(ps, ps).map!foo().reduce!bar();
const r1 = spam([S(), S()]); // Error
void main() {
    const r2 = spam([S(), S()]); // OK

Output, DMD 2.061alpha:

...\dmd2\src\phobos\std\conv.d(3393): Error: cannot dereference invalid pointer
...\dmd2\src\phobos\std\range.d(3714):        called from here:
...\dmd2\src\phobos\std\algorithm.d(428):        called from here:
...\dmd2\src\phobos\std\algorithm.d(428):        called from here:
...\dmd2\src\phobos\std\algorithm.d(697):        called from here:
temp.d(12):        called from here: reduce(map(zip(ps,ps)))
temp.d(14):        called from here: spam([S(),S()])

I have asked about it here:
http://forum.dlang.org/thread/llfilfmmkvobsijdvrhu forum.dlang.org

Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 04 2012