www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - A tuple bug?

reply Max Samukha <samukha voliacable.com> writes:
The output when compiling the code below is "1, 1" while it should be
"1, 2".  When 'names' declarations are commented out, the output is
correct.

import std.stdio;

template Foo(A...)
{
    static if (A.length > 3)
    {
        const char[] names = A[0] ~ ", " ~ Foo!(A[3..$]).names;
        const char[] values = A[1].stringof ~ ", " ~
Foo!(A[3..$]).values;
    }
    else
    {
        static assert(A.length == 3);

        const char[] names = A[0];
        const char[] values = A[1].stringof;
    }
}

void main()
{
    pragma(msg, Foo!(
        "One", 1, "First item",
        "Two", 2, "Second item").values
    );
}

Is it a bug?
Apr 23 2007
parent reply =?ISO-8859-1?Q?Jari-Matti_M=E4kel=E4?= <jmjmak utu.fi.invalid> writes:
Max Samukha wrote:
 The output when compiling the code below is "1, 1" while it should be
 "1, 2".  When 'names' declarations are commented out, the output is
 correct.
<snip>
 Is it a bug?
Yeah, something fishy is happening here (tested with dmd 1.013). This code template Foo(A...) { const char[] values = A[1].stringof; pragma(msg, A.length.stringof); // 1) pragma(msg, values); } void main() { alias Foo!(1,1,1,1,1) val; } returns 5 5 but commenting the line 1) makes it return '1'. Also the compiler should be able to infer the type of 'values' when 'char[]' is omitted, but it doesn't. So, at least two bugs here.
Apr 23 2007
parent Max Samukha <samukha voliacable.com> writes:
On Mon, 23 Apr 2007 23:42:37 +0300, Jari-Matti Makela
<jmjmak utu.fi.invalid> wrote:

Max Samukha wrote:
 The output when compiling the code below is "1, 1" while it should be
 "1, 2".  When 'names' declarations are commented out, the output is
 correct.
<snip>
 Is it a bug?
Yeah, something fishy is happening here (tested with dmd 1.013). This code template Foo(A...) { const char[] values = A[1].stringof; pragma(msg, A.length.stringof); // 1) pragma(msg, values); } void main() { alias Foo!(1,1,1,1,1) val; } returns 5 5 but commenting the line 1) makes it return '1'. Also the compiler should be able to infer the type of 'values' when 'char[]' is omitted, but it doesn't. So, at least two bugs here.
Thanks. I've posted this to bugzilla
Apr 24 2007