June 25, 2012
On Sunday, June 24, 2012 19:03:17 Namespace wrote:
> > This might work:
> > 
> > this(U)(U obj)
> > 
> >     if(is(U : T) && !is(U == typeof(null)))
> > 
> > {
> > }
> > 
> > 
> > - Jonathan M Davis
> 
> Interesting. With or wihtout that, if i add a method to Foo it prints "Stack overflow" also.
> 
> http://dpaste.dzfl.pl/91dad66c
> 
> Can you explain that?

Wait, you have a template mixin inside of Foo which passes Foo to it? I don't know if you can get away with that or not, since you're trying to pass a type to a template while you're adding stuff to it via that template. So, the type is incomplete. I'm willing to be that that's your problem, but I don't know.

- Jonathan M Davis
June 25, 2012
> Wait, you have a template mixin inside of Foo which passes Foo to it? I don't
> know if you can get away with that or not, since you're trying to pass a type
> to a template while you're adding stuff to it via that template. So, the type
> is incomplete. I'm willing to be that that's your problem, but I don't know.
>
> - Jonathan M Davis

If so, the problem would have to solved if i switch from a mixin to an abstract class. Or not?
Or have you any other idea?
June 25, 2012
On Monday, June 25, 2012 08:24:59 Namespace wrote:
> > Wait, you have a template mixin inside of Foo which passes Foo
> > to it? I don't
> > know if you can get away with that or not, since you're trying
> > to pass a type
> > to a template while you're adding stuff to it via that
> > template. So, the type
> > is incomplete. I'm willing to be that that's your problem, but
> > I don't know.
> > 
> > - Jonathan M Davis
> 
> If so, the problem would have to solved if i switch from a mixin
> to an abstract class. Or not?
> Or have you any other idea?

If you don't need to use any compile-time reflection on the type itself (i.e. you just need its name), you can use a string mixin.

- Jonathan M Davis
June 25, 2012
> If you don't need to use any compile-time reflection on the type itself (i.e.
> you just need its name), you can use a string mixin.
>
> - Jonathan M Davis

You mean i should pack the whole mixin template in a string?
Isn't that a little bit ugly?
June 25, 2012
On Monday, June 25, 2012 10:18:19 Namespace wrote:
> > If you don't need to use any compile-time reflection on the
> > type itself (i.e.
> > you just need its name), you can use a string mixin.
> > 
> > - Jonathan M Davis
> 
> You mean i should pack the whole mixin template in a string? Isn't that a little bit ugly?

More or less yeah. You generate the code as a string and then mix it in. As it's a string, it's really easy to manipulate, and if you lay out the strings properly, it's not really even particularly hard to read. Personally, I never use template mixins, and I get the impression that string mixins get used a lot more than template mixins do.

- Jonathan M Davis
June 25, 2012
On 06/25/2012 02:48 AM, Jonathan M Davis wrote:
> On Sunday, June 24, 2012 19:03:17 Namespace wrote:
>>> This might work:
>>>
>>> this(U)(U obj)
>>>
>>>      if(is(U : T)&&  !is(U == typeof(null)))
>>>
>>> {
>>> }
>>>
>>>
>>> - Jonathan M Davis
>>
>> Interesting. With or wihtout that, if i add a method to Foo it
>> prints "Stack overflow" also.
>>
>> http://dpaste.dzfl.pl/91dad66c
>>
>> Can you explain that?
>
> Wait, you have a template mixin inside of Foo which passes Foo to it? I don't
> know if you can get away with that or not, since you're trying to pass a type
> to a template while you're adding stuff to it via that template. So, the type
> is incomplete. I'm willing to be that that's your problem, but I don't know.
>
> - Jonathan M Davis

This is fine. I am doing it all the time.
Why are we discussing this compiler bug on the main newsgroup though?
June 25, 2012
On Monday, June 25, 2012 13:01:47 Timon Gehr wrote:
> On 06/25/2012 02:48 AM, Jonathan M Davis wrote:
> > On Sunday, June 24, 2012 19:03:17 Namespace wrote:
> >>> This might work:
> >>> 
> >>> this(U)(U obj)
> >>> 
> >>>      if(is(U : T)&&  !is(U == typeof(null)))
> >>> 
> >>> {
> >>> }
> >>> 
> >>> 
> >>> - Jonathan M Davis
> >> 
> >> Interesting. With or wihtout that, if i add a method to Foo it prints "Stack overflow" also.
> >> 
> >> http://dpaste.dzfl.pl/91dad66c
> >> 
> >> Can you explain that?
> > 
> > Wait, you have a template mixin inside of Foo which passes Foo to it? I don't know if you can get away with that or not, since you're trying to pass a type to a template while you're adding stuff to it via that template. So, the type is incomplete. I'm willing to be that that's your problem, but I don't know.
> > 
> > - Jonathan M Davis
> 
> This is fine. I am doing it all the time.

If it works, then it works, but it surprises me a bit, given that you can't do that with template declarations normally.

> Why are we discussing this compiler bug on the main newsgroup though?

We're not discussing this on the main newsgroup. This is d-learn.

- Jonathan M Davis
June 25, 2012
Fine. But nothing of them explain the Stack overflow if i add an additional method or disable/add an additional ctor.
June 25, 2012
On 06/25/2012 02:18 PM, Namespace wrote:
> Fine. But nothing of them explain the Stack overflow if i add an
> additional method or disable/add an additional ctor.

It does not have to be explained: it is a compiler bug.
June 25, 2012
On Monday, 25 June 2012 at 15:39:19 UTC, Timon Gehr wrote:
> On 06/25/2012 02:18 PM, Namespace wrote:
>> Fine. But nothing of them explain the Stack overflow if i add an
>> additional method or disable/add an additional ctor.
>
> It does not have to be explained: it is a compiler bug.

Then it will take months or years until it is fixed ... too bad.

And that Ref!(Foo) rf = new Foo(); ends even with "Stack overflow" and Ref!(Foo) rf2 = new Ref!(Foo)(new Foo()); not has the same explanation "Compiler Bug", hm?