ability to explicitly cast maybe pointers to each other

master
Andrew Kelley 2016-02-07 01:25:04 -07:00
parent 4174134108
commit 7f6b0ba6ea
2 changed files with 16 additions and 0 deletions

View File

@ -3702,6 +3702,15 @@ static TypeTableEntry *analyze_cast_expr(CodeGen *g, ImportTableEntry *import, B
return resolve_cast(g, context, node, expr_node, wanted_type, CastOpPointerReinterpret, false); return resolve_cast(g, context, node, expr_node, wanted_type, CastOpPointerReinterpret, false);
} }
// explicit cast from maybe pointer to another maybe pointer
if (actual_type->id == TypeTableEntryIdMaybe &&
actual_type->data.maybe.child_type->id == TypeTableEntryIdPointer &&
wanted_type->id == TypeTableEntryIdMaybe &&
wanted_type->data.maybe.child_type->id == TypeTableEntryIdPointer)
{
return resolve_cast(g, context, node, expr_node, wanted_type, CastOpPointerReinterpret, false);
}
// explicit cast from child type of maybe type to maybe type // explicit cast from child type of maybe type to maybe type
if (wanted_type->id == TypeTableEntryIdMaybe) { if (wanted_type->id == TypeTableEntryIdMaybe) {
if (types_match_const_cast_only(wanted_type->data.maybe.child_type, actual_type)) { if (types_match_const_cast_only(wanted_type->data.maybe.child_type, actual_type)) {

View File

@ -208,3 +208,10 @@ fn wants_fn_with_void(f: fn()) { }
fn fn_with_unreachable() -> unreachable { fn fn_with_unreachable() -> unreachable {
unreachable {} unreachable {}
} }
#attribute("test")
fn explicit_cast_maybe_pointers() {
const a: ?&i32 = undefined;
const b: ?&f32 = (?&f32)(a);
}