D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1692 - Abstract class dynamic creation bug
Summary: Abstract class dynamic creation bug
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D1 (retired)
Hardware: All All
: P2 major
Assignee: No Owner
URL:
Keywords: patch, wrong-code
: 2453 6667 (view as issue list)
Depends on:
Blocks:
 
Reported: 2007-11-24 11:38 UTC by Jaroslav Kroft
Modified: 2014-02-24 15:59 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jaroslav Kroft 2007-11-24 11:38:38 UTC
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....
Comment 1 Max Samukha 2008-11-25 08:06:13 UTC
*** Bug 2453 has been marked as a duplicate of this bug. ***
Comment 2 Gide Nwawudu 2009-04-23 05:01:45 UTC
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
}
Comment 3 yebblies 2011-07-01 02:57:29 UTC
The bug is primarily in druntime, but requires a dmd change to pass more information along.

https://github.com/D-Programming-Language/dmd/pull/186
https://github.com/D-Programming-Language/druntime/pull/34
Comment 4 yebblies 2011-09-14 05:36:40 UTC
*** Issue 6667 has been marked as a duplicate of this issue. ***