www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1692] New: Abstract class dynamic creation bug

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

           Summary: Abstract class dynamic creation bug
           Product: D
           Version: 1.023
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: jaroslav.kroft seznam.cz


Hi, 
here is some piece of code which most probably doesn't work one expect to.

version (Tango) {
  import tango.io.Console;
  pragma(lib, "tango-user-dmd");
} else {
  import std.stdio;
}

class AbstractError: Error {
  this (char[] msg = null) {
    super(msg);
  }
}

abstract class Dummy {
  public {
    this() {
      if (!this) {
        throw new AbstractError();
      }
    }
  }

  char[] Value();
}

int main(char[][] args)
{
  ClassInfo ci = ClassInfo.find("hello.Dummy");
  if (ci) {
    Object o = ci.create();
    if (o) {
version (Tango) {
      Cout(o.toUtf8);
} else {
  writef(o.toString);
}
    }
  }
  return 0;
}

This code would compile without any error, but when you try to run, you will
receive AV most probably directly in the constructor. I guess that in this case
the call of ClassInfo.create should either return null or throw some kind of
error....


-- 
Nov 24 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1692


samukha voliacable.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |samukha voliacable.com




------- Comment #1 from samukha voliacable.com  2008-11-25 08:06 -------
*** Bug 2453 has been marked as a duplicate of this bug. ***


-- 
Nov 25 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1692





------- Comment #2 from gide nwawudu.com  2009-04-23 05:01 -------
Added example from Bug 2453.

abstract class C {
}

void main()
{
    auto c = cast(C)C.classinfo.create();
    assert(c is null); // should pass or classinfo.create should throw an
exception
}


-- 
Apr 23 2009