On 10/03/2013 11:10 PM, deadalnix wrote:

> On Friday, 4 October 2013 at 05:07:53 UTC, Zhouxuan wrote:
>> ////////////////////////////////////////////////////////////
>> //case 1
>>
>> class A
>> {
>>     abstract void foo();
>> }
>>
>> class B : A
>> {
>>     static if( __traits(isAbstractClass, typeof(this) ))
>
> this is invalid here. Not sure what you try to achieve via this static if.

Well, obviously that is the reason for the bug. :) I think Zhouxuan thinks that it is an 'abstract' bug but actually it is some sort of __traits caching issue.

It would indeed be weird for isAbstractClass to delay its value until the whole class definition is seen.

Instead, what seems to happen is that isAbstractClass caches the first value that it determines and perhaps at least for consistency uses that value. Moving isAbstractClass after the definition of B.foo removes the issue in this case:

class A
{
    abstract void foo();
}

class B : A
{
    override void foo()
    {
    }

    // Added by Ali:
    pragma(msg, __traits(isAbstractClass, typeof(this)));

    static if( __traits(isAbstractClass, typeof(this) ))
    {
    }
}

void main()
{
    B b = new B();    // now compiles
}

Ali

Reply via email to