Fix issue 1024: allow classes to be cast to typeof(null)

... and always return null in that case.
This commit is contained in:
Martin 2015-08-16 21:43:24 +02:00
parent 532353f5a2
commit 5d71dc38df

View file

@ -236,6 +236,11 @@ DValue* DtoCastClass(Loc& loc, DValue* val, Type* _to)
DImValue im(Type::tsize_t, v); DImValue im(Type::tsize_t, v);
return DtoCastInt(loc, &im, _to); return DtoCastInt(loc, &im, _to);
} }
// class -> typeof(null)
else if (to->ty == Tnull) {
IF_LOG Logger::println("to %s", to->toChars());
return new DImValue(_to, LLConstant::getNullValue(DtoType(_to)));
}
// must be class/interface // must be class/interface
assert(to->ty == Tclass); assert(to->ty == Tclass);