ability to explicitly cast maybe pointers to each other
parent
4174134108
commit
7f6b0ba6ea
|
@ -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);
|
||||
}
|
||||
|
||||
// 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
|
||||
if (wanted_type->id == TypeTableEntryIdMaybe) {
|
||||
if (types_match_const_cast_only(wanted_type->data.maybe.child_type, actual_type)) {
|
||||
|
|
|
@ -208,3 +208,10 @@ fn wants_fn_with_void(f: fn()) { }
|
|||
fn fn_with_unreachable() -> unreachable {
|
||||
unreachable {}
|
||||
}
|
||||
|
||||
|
||||
#attribute("test")
|
||||
fn explicit_cast_maybe_pointers() {
|
||||
const a: ?&i32 = undefined;
|
||||
const b: ?&f32 = (?&f32)(a);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue