Comment #0 by bus_dbugzilla — 2012-07-24T15:49:52Z
void foo(T...)(T args)
{
foreach(T arg; args)
{}
}
void main()
{
foo("", [""]);
}
Works in 2.059, but not in 2.060 beta:
testTypeSafeVarArg.d(1): Error: cannot implicitly convert expression (_param_0) of type string to string[]
testTypeSafeVarArg.d(1): Error: cannot implicitly convert expression (_param_1) of type string[] to string
testTypeSafeVarArg.d(9): Error: template instance testTypeSafeVarArg.foo!(string,string[]) error instantiating
Comment #1 by code — 2012-07-24T16:04:33Z
foreach(T arg; args) – sure about that T there?
Comment #2 by simen.kjaras — 2012-07-24T16:08:58Z
(In reply to comment #1)
> foreach(T arg; args) – sure about that T there?
As Nick stated in the report, it compiles under 2.059. However,
void foo(T...)(T args)
{
foreach(T arg; args)
{
pragma(msg, typeof(arg));
pragma(msg, T);
}
}
void main()
{
foo("", [""]);
}
Should prove that the T is being ignored in 2.059, and as such it accepts invalid code. This is not a regression, it's a fix.
Comment #3 by bus_dbugzilla — 2012-07-24T17:32:58Z
Fuck, good catch! Never mind me. Carry on ;)
Comment #4 by k.hara.pg — 2012-07-24T19:24:32Z
The original issue that fixed in 2.060beta is bug 5435.
Then, if you iterate a tuple that has heterogeneous elements, you should not add type for foreach argument.