| author | |
| committer | |
| log | 11ca38a4e9c637bf6ff635f4f62634edaf89f853 |
| tree | d5cce0cbb97bd4c7756b591066d5f10152aa8bb1 |
| parent | af95e1557214df4a1a34a712efc2f8dafb502c82 |
closes #11533 files changed, 12 insertions(+), 1 deletions(-)
src/ir.cpp+2-1| ... | @@ -7985,9 +7985,10 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry | ... | @@ -7985,9 +7985,10 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry |
| 7985 | 7985 | ||
| 7986 | // * and [*] can do a const-cast-only to ?* and ?[*], respectively | 7986 | // * and [*] can do a const-cast-only to ?* and ?[*], respectively |
| 7987 | // but not if there is a mutable parent pointer | 7987 | // but not if there is a mutable parent pointer |
| 7988 | // and not if the pointer is zero bits | ||
| 7988 | if (!wanted_is_mutable && wanted_type->id == TypeTableEntryIdOptional && | 7989 | if (!wanted_is_mutable && wanted_type->id == TypeTableEntryIdOptional && |
| 7989 | wanted_type->data.maybe.child_type->id == TypeTableEntryIdPointer && | 7990 | wanted_type->data.maybe.child_type->id == TypeTableEntryIdPointer && |
| 7990 | actual_type->id == TypeTableEntryIdPointer) | 7991 | actual_type->id == TypeTableEntryIdPointer && type_has_bits(actual_type)) |
| 7991 | { | 7992 | { |
| 7992 | ConstCastOnly child = types_match_const_cast_only(ira, | 7993 | ConstCastOnly child = types_match_const_cast_only(ira, |
| 7993 | wanted_type->data.maybe.child_type, actual_type, source_node, wanted_is_mutable); | 7994 | wanted_type->data.maybe.child_type, actual_type, source_node, wanted_is_mutable); |
test/behavior.zig+1| ... | @@ -35,6 +35,7 @@ comptime { | ... | @@ -35,6 +35,7 @@ comptime { |
| 35 | _ = @import("cases/math.zig"); | 35 | _ = @import("cases/math.zig"); |
| 36 | _ = @import("cases/merge_error_sets.zig"); | 36 | _ = @import("cases/merge_error_sets.zig"); |
| 37 | _ = @import("cases/misc.zig"); | 37 | _ = @import("cases/misc.zig"); |
| 38 | _ = @import("cases/optional.zig"); | ||
| 38 | _ = @import("cases/namespace_depends_on_compile_var/index.zig"); | 39 | _ = @import("cases/namespace_depends_on_compile_var/index.zig"); |
| 39 | _ = @import("cases/new_stack_call.zig"); | 40 | _ = @import("cases/new_stack_call.zig"); |
| 40 | _ = @import("cases/null.zig"); | 41 | _ = @import("cases/null.zig"); |
test/cases/optional.zig created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | const assert = @import("std").debug.assert; | ||
| 2 | |||
| 3 | pub const EmptyStruct = struct {}; | ||
| 4 | |||
| 5 | test "optional pointer to size zero struct" { | ||
| 6 | var e = EmptyStruct{}; | ||
| 7 | var o: ?*EmptyStruct = &e; | ||
| 8 | assert(o != null); | ||
| 9 | } | ||