From: Brendan Hansen Date: Thu, 28 Sep 2023 21:56:44 +0000 (-0500) Subject: bugfix: field selector on pointers to unions X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=a6bebd23cee425311c42609a184e1be749970c76;p=onyx.git bugfix: field selector on pointers to unions --- diff --git a/compiler/src/wasm_emit.c b/compiler/src/wasm_emit.c index a361da0a..7afd7c6d 100644 --- a/compiler/src/wasm_emit.c +++ b/compiler/src/wasm_emit.c @@ -3584,8 +3584,15 @@ EMIT_FUNC(expression, AstTyped* expr) { emit_stack_address(mod, &code, intermediate_local + type_alignment_of(field->type), field->token); WIL(NULL, WI_LOCAL_GET, source_base_ptr); - WIL(NULL, WI_I32_CONST, type_alignment_of(field->expr->type)); + + if (type_is_pointer(field->expr->type)) { + WIL(NULL, WI_I32_CONST, type_alignment_of(field->expr->type->Pointer.elem)); + } else { + WIL(NULL, WI_I32_CONST, type_alignment_of(field->expr->type)); + } + WI(NULL, WI_I32_ADD); + WIL(NULL, WI_I32_CONST, type_size_of(field->type->Union.variants_ordered[1]->type)); emit_wasm_copy(mod, &code, NULL);