Commit 7f6b0ba6ea

Andrew Kelley <superjoe30@gmail.com>
2016-02-07 09:25:04
ability to explicitly cast maybe pointers to each other
1 parent 4174134
Changed files (2)
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)) {
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);
+}