More bugs...

James Miller james at aatch.net
Fri Apr 27 22:13:31 PDT 2012


On Saturday, 28 April 2012 at 04:45:59 UTC, Mehrdad wrote:
> Okay, final exams are coming up again, and so are my bugs (I 
> have no idea what the correlation is, don't ask...)
> I guess I should post this on bugzilla, but oh well... I 
> continued the thread instead.
>
> Try compiling this (I did this on Windows, DMD 2.059):
>
> void main() { Foo!(int[])([[1], [2]]); }
> struct Foo(T) { auto foo() { Foo!(T[]) t; return t; } }

You expected that to work? Extra extra, infinite recursion is 
infinite! You are asking the compiler to instantiate Foo with the 
type int[], then use that type to instantiate Foo with int[][], 
which then instantiates Foo with type int[][][].

Try thinking about your code before mouthing off here. Would you 
fault C for causing a stack overflow in this case:

int rec(int a){
   return rec(a + 1);
}

I mean what did you expect, that the compiler could magically 
create infinite types? I can't even see where you might have gone 
wrong here, since the code is so simple. What I can see is that 
the constructor wouldn't work because there are no fields. I can 
see that you have some very strange ideas about templates, Foo(T) 
instantiates Foo(T[]), which is a different type, so it goes 
through and instantiates Foo(T[][]) which is, again, a different 
type.

Think before declaring D to have bugs.

--
James Miller


More information about the Digitalmars-d mailing list