mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Merge pull request #4062 from laytan/fix-switch-over-internal-pointer-union
fix type switching over internal pointer union
This commit is contained in:
@@ -1646,7 +1646,7 @@ gb_internal void lb_build_type_switch_stmt(lbProcedure *p, AstTypeSwitchStmt *ss
|
|||||||
union_data = lb_emit_conv(p, parent_ptr, t_rawptr);
|
union_data = lb_emit_conv(p, parent_ptr, t_rawptr);
|
||||||
Type *union_type = type_deref(parent_ptr.type);
|
Type *union_type = type_deref(parent_ptr.type);
|
||||||
if (is_type_union_maybe_pointer(union_type)) {
|
if (is_type_union_maybe_pointer(union_type)) {
|
||||||
tag = lb_emit_conv(p, lb_emit_comp_against_nil(p, Token_NotEq, union_data), t_int);
|
tag = lb_emit_conv(p, lb_emit_comp_against_nil(p, Token_NotEq, parent_value), t_int);
|
||||||
} else if (union_tag_size(union_type) == 0) {
|
} else if (union_tag_size(union_type) == 0) {
|
||||||
tag = {}; // there is no tag for a zero sized union
|
tag = {}; // there is no tag for a zero sized union
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package test_internal
|
||||||
|
|
||||||
|
import "core:log"
|
||||||
|
import "core:testing"
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_internal_pointer_union_switch :: proc(t: ^testing.T) {
|
||||||
|
foo: Maybe(^int)
|
||||||
|
|
||||||
|
switch _ in foo {
|
||||||
|
case ^int:
|
||||||
|
log.error("incorrect case")
|
||||||
|
case nil:
|
||||||
|
}
|
||||||
|
|
||||||
|
v := 1
|
||||||
|
foo = &v
|
||||||
|
|
||||||
|
switch _ in foo {
|
||||||
|
case ^int:
|
||||||
|
case nil:
|
||||||
|
log.error("incorrect case")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user