Thread overview
A tuple bug?
Apr 23, 2007
Max Samukha
Apr 24, 2007
Max Samukha
April 23, 2007
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?
April 23, 2007
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.
April 24, 2007
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