zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 7f6b0ba6eafd566a5a9243286ba59fc0e4587d30 (tree)
parent 4174134108fdef462c2483f4ca5aa40dd6398d55
Author: Andrew Kelley <superjoe30@gmail.com>
Date:   Sun,  7 Feb 2016 01:25:04 -0700

ability to explicitly cast maybe pointers to each other

Diffstat:
Msrc/analyze.cpp | 9+++++++++
Mtest/self_hosted.zig | 7+++++++
2 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/src/analyze.cpp b/src/analyze.cpp @@ -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)) { diff --git a/test/self_hosted.zig b/test/self_hosted.zig @@ -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); +}