mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-18 13:53:14 +01:00
Fixed #54 — Error: invalid cast from 'typeof(null)' to 'void*'
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user