authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-02-07 01:25:04-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-02-07 01:25:04-07:00
log7f6b0ba6eafd566a5a9243286ba59fc0e4587d30
treeae46e6a16e53adae3831978cf7f72c4629c42a19
parent4174134108fdef462c2483f4ca5aa40dd6398d55

ability to explicitly cast maybe pointers to each other


2 files changed, 16 insertions(+), 0 deletions(-)

src/analyze.cpp+9
......@@ -3702,6 +3702,15 @@ static TypeTableEntry *analyze_cast_expr(CodeGen *g, ImportTableEntry *import, B
37023702 return resolve_cast(g, context, node, expr_node, wanted_type, CastOpPointerReinterpret, false);
37033703 }
37043704
3705 // explicit cast from maybe pointer to another maybe pointer
3706 if (actual_type->id == TypeTableEntryIdMaybe &&
3707 actual_type->data.maybe.child_type->id == TypeTableEntryIdPointer &&
3708 wanted_type->id == TypeTableEntryIdMaybe &&
3709 wanted_type->data.maybe.child_type->id == TypeTableEntryIdPointer)
3710 {
3711 return resolve_cast(g, context, node, expr_node, wanted_type, CastOpPointerReinterpret, false);
3712 }
3713
37053714 // explicit cast from child type of maybe type to maybe type
37063715 if (wanted_type->id == TypeTableEntryIdMaybe) {
37073716 if (types_match_const_cast_only(wanted_type->data.maybe.child_type, actual_type)) {
test/self_hosted.zig+7
......@@ -208,3 +208,10 @@ fn wants_fn_with_void(f: fn()) { }
208208fn fn_with_unreachable() -> unreachable {
209209 unreachable {}
210210}
211
212
213#attribute("test")
214fn explicit_cast_maybe_pointers() {
215 const a: ?&i32 = undefined;
216 const b: ?&f32 = (?&f32)(a);
217}