www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11169] New: cannot create instance of abstract class

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11169

           Summary: cannot create instance of abstract class
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: pycerl qq.com


--- Comment #0 from Zhouxuan <pycerl qq.com> 2013-10-03 22:19:23 PDT ---
////////////////////////////////////////////////////////////
//case 1

class A
{
    abstract void foo();
}

class B : A
{
    static if( __traits(isAbstractClass, typeof(this) ))
    {
    }

    override void foo()
    {
    }
}

void main()
{
    B b = new B();
}

//Error: cannot create instance of abstract class B
////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////
//case 2

abstract class A
{
    void foo();
}

class B : A
{
    static if( __traits(isAbstractClass, typeof(this) ))
    {
    }

    override void foo()
    {
    }
}

void main()
{
    B b = new B();
}

//Okay
////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////
//case 3

class A
{
    abstract void foo();
}

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

void main()
{
    B b = new B();
}

//Okay
////////////////////////////////////////////////////////////

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 03 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11169


Ali Cehreli <acehreli yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |acehreli yahoo.com


--- Comment #1 from Ali Cehreli <acehreli yahoo.com> 2013-10-03 23:27:26 PDT ---
If others agree, please change the summary to something like

  __traits(isAbstractClass) uses the definition that it knows so far, not the
whole definition of the class


In any case, it would be a chicken and egg problem if static if tried to
complete the definition of the class.

Ali

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 03 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11169



--- Comment #2 from Zhouxuan <pycerl qq.com> 2013-10-03 23:48:02 PDT ---
(In reply to comment #1)
 If others agree, please change the summary to something like
 
   __traits(isAbstractClass) uses the definition that it knows so far, not the
 whole definition of the class
 
 
 In any case, it would be a chicken and egg problem if static if tried to
 complete the definition of the class.
 
 Ali
How about follow the rules of checking recursive alias? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 03 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11169


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com


--- Comment #3 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-10-04
04:32:31 PDT ---
(In reply to comment #1)
 If others agree, please change the summary to something like
 
   __traits(isAbstractClass) uses the definition that it knows so far, not the
 whole definition of the class
Internal note: The issue is that __traits(isAbstractClass) has side-effects. It will call `ClassDeclaration::isAbstract`, but this will not only return the result but also set the internal `isabstract` field for the class (damn getter functions with side-effects..). I guess semantic() wasn't called on the class at that point. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 04 2013