www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8900] New: Using zip with char[] sometimes fails to compile

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

           Summary: Using zip with char[] sometimes fails to compile
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: hsteoh quickfur.ath.cx



CODE:
-----------------------------
import std.algorithm;
import std.range;

version = Bug;

auto cartesianProd(R1,R2)(R1 range1, R2 range2)
{
    version(Bug)
    {  
        ElementType!R2 a;
        return zip(range1.save, repeat(a));
    }
    else
    {  
        // For some crazy reason, this one works.
        ElementType!R1 a;
        return zip(repeat(a), range2.save);
    }
}

void main() {
    auto arr = cartesianProd([1,2], ['a','b']);
}
------------------------------

DMD output:
------------------------------
/usr/src/d/phobos/std/format.d(1937): Error: template std.range.walkLength does
not match any function template declaration
/usr/src/d/phobos/std/range.d(1321): Error: template std.range.walkLength
cannot deduce template function from argument types !()(Repeat!(dchar))
/usr/src/d/phobos/std/format.d(2495): Error: template instance
std.format.formatRange!(Appender!(string),Repeat!(dchar),char) error
instantiating
/usr/src/d/phobos/std/format.d(2172):        instantiated from here:
formatValue!(Appender!(string),Repeat!(dchar),char)
/usr/src/d/phobos/std/typecons.d(552):        instantiated from here:
formatElement!(Appender!(string),Repeat!(dchar),char)
/usr/src/d/phobos/std/range.d(3700):        instantiated from here:
Tuple!(int[],Repeat!(dchar))
/usr/src/d/phobos/std/range.d(4060):        ... (1 instantiations, -v to show)
...
test.d(11):        instantiated from here: zip!(int[],Repeat!(dchar))
test.d(22):        instantiated from here: cartesianProd!(int[],char[])
/usr/src/d/phobos/std/format.d(2172): Error: template instance
std.format.formatValue!(Appender!(string),Repeat!(dchar),char) error
instantiating
/usr/src/d/phobos/std/typecons.d(552):        instantiated from here:
formatElement!(Appender!(string),Repeat!(dchar),char)
/usr/src/d/phobos/std/range.d(3700):        instantiated from here:
Tuple!(int[],Repeat!(dchar))
/usr/src/d/phobos/std/range.d(4060):        instantiated from here:
Zip!(int[],Repeat!(dchar))
test.d(11):        instantiated from here: zip!(int[],Repeat!(dchar))
test.d(22):        instantiated from here: cartesianProd!(int[],char[])
/usr/src/d/phobos/std/typecons.d(552): Error: template instance
std.format.formatElement!(Appender!(string),Repeat!(dchar),char) error
instantiating
/usr/src/d/phobos/std/range.d(3700):        instantiated from here:
Tuple!(int[],Repeat!(dchar))
/usr/src/d/phobos/std/range.d(4060):        instantiated from here:
Zip!(int[],Repeat!(dchar))
test.d(11):        instantiated from here: zip!(int[],Repeat!(dchar))
test.d(22):        instantiated from here: cartesianProd!(int[],char[])
/usr/src/d/phobos/std/range.d(4060): Error: template instance
std.range.Zip!(int[],Repeat!(dchar)) error instantiating
test.d(11):        instantiated from here: zip!(int[],Repeat!(dchar))
test.d(22):        instantiated from here: cartesianProd!(int[],char[])
test.d(11): Error: template instance std.range.zip!(int[],Repeat!(dchar)) error
instantiating
test.d(22):        instantiated from here: cartesianProd!(int[],char[])
test.d(22): Error: template instance test.cartesianProd!(int[],char[]) error
instantiating
------------------------------

Oddly enough, commenting out the "version = Bug" line at the top (which
switches the order of a few parameters to zip) makes the problem go away.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 26 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8900


Peter Alexander <peter.alexander.au gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |peter.alexander.au gmail.co
                   |                            |m



16:47:21 PDT ---
What version of DMD are you using? I can't reproduce with 2.060, or from git
HEAD.

http://dpaste.dzfl.pl/949738af

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 26 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8900




Hmm that is strange. I'm using git HEAD too, for dmd, druntime, and phobos. I
just did a git pull and make clean ; make, and I'm still getting the same
error.

I'm on 64-bit Linux, if that makes any difference (though I can't see why it
should).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 26 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8900




P.S. I meant that I did a git pull, make clean, and make, for all three, dmd,
druntime, phobos (in that order). Still same error.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 26 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8900




03:25:26 PDT ---

 Hmm that is strange. I'm using git HEAD too, for dmd, druntime, and phobos. I
 just did a git pull and make clean ; make, and I'm still getting the same
 error.
My bad, I get the bug now on git HEAD. The break was caused by this: https://github.com/D-Programming-Language/phobos/pull/880 The problem is that walkLength is called on the second range, which is infinite. This makes no sense, which is the reason for that pull request. Where is walkLength called? Zip has a Tuple!R element. And Tuple!R's toString function tries to print out the range. Why is it only called in version=Bug? Because formatElement is specialised for strings, and just happens to not call walkLength eventually. I'll fix this, but needless to say this is a mess. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 27 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8900




03:57:28 PDT ---
https://github.com/D-Programming-Language/phobos/pull/901

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 27 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8900




Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/a00c3c825c863c0c53cb69ab907c7be539bf51e4
Fix bug 8900 - Zip with infinite range fails.

`std.range.Zip` contains a `Tuple`, whose `toString()` function calls
`formatElement` which eventually calls this function, leading to a static call
to `walkLength` on infinite ranges. Since pul request 880, `walkLength` doesn't
work with infinite ranges, so it fails to compile.

This change ensures that `walkLength` is called with only valid range types.

Bug: http://d.puremagic.com/issues/show_bug.cgi?id=8900

https://github.com/D-Programming-Language/phobos/commit/259cd23d67b8025eebc5c46e3756e2c98337a663


Fix bug 8900 - Zip with infinite char range fails.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 13 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8900


hsteoh quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED



Confirmed fixed in latest git dmd (adcdfd7bd0cdea8b0f79cef4a687cd4eb77b3c53).

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