Fixed #54 — Error: invalid cast from 'typeof(null)' to 'void*'

This commit is contained in:
Alexey Prokhin
2012-01-09 15:13:56 +04:00
parent b41688a0b8
commit dbb6528c95

View File

@@ -736,6 +736,26 @@ DValue* DtoCastDelegate(Loc& loc, DValue* val, Type* to)
}
}
DValue* DtoCastNull(Loc& loc, DValue* val, Type* to)
{
Type* totype = to->toBasetype();
LLType* tolltype = DtoType(to);
if (totype->ty == Tpointer)
{
if (Logger::enabled())
Logger::cout() << "cast null to pointer: " << *tolltype << '\n';
LLValue *rval = DtoBitCast(val->getRVal(), tolltype);
return new DImValue(to, rval);
}
else
{
error(loc, "invalid cast from null to '%s'", to->toChars());
fatal();
}
}
DValue* DtoCast(Loc& loc, DValue* val, Type* to)
{
Type* fromtype = val->getType()->toBasetype();
@@ -775,6 +795,9 @@ DValue* DtoCast(Loc& loc, DValue* val, Type* to)
else if (fromtype->ty == Tdelegate) {
return DtoCastDelegate(loc, val, to);
}
else if (fromtype->ty == Tnull) {
return DtoCastNull(loc, val, to);
}
else if (fromtype->ty == totype->ty) {
return val;
} else {