Comment #0 by jaroslav.kroft — 2007-11-24T11:38:38Z
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 by samukha — 2008-11-25T08:06:13Z
*** Bug 2453 has been marked as a duplicate of this bug. ***
Comment #2 by gide — 2009-04-23T05:01:45Z
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
}