From: Jérémie Astor Date: Thu, 15 Jul 2021 14:46:36 +0000 (+0200) Subject: :bug: Fix unions X-Git-Tag: nightly~540 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=48bf740ff094f192583364af611b4fd05a71bfc1;p=gwion.git :bug: Fix unions --- diff --git a/src/emit/emit.c b/src/emit/emit.c index 4923dea4..d2da9115 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1150,7 +1150,7 @@ ANN static m_bool _emit_exp_call(const Emitter emit, const Exp_Call *exp_call) { const Type t = actual_type(emit->gwion, exp_call->func->type); const Func f = t->info->func; if (is_fptr(emit->gwion, t) || strstr(emit->code->name, "ork~") || - (f != emit->env->func || f->value_ref->from->owner_class)) + (f != emit->env->func || (f && f->value_ref->from->owner_class))) CHECK_BB(prepare_call(emit, exp_call)); else CHECK_BB(emit_func_args(emit, exp_call)); diff --git a/src/lib/union.c b/src/lib/union.c index d01aff89..6cc7d0e6 100644 --- a/src/lib/union.c +++ b/src/lib/union.c @@ -133,7 +133,6 @@ static OP_CHECK(opck_union_ctor) { static INSTR(UnionCtor) { POP_REG(shred, instr->m_val2); - POP_REG(shred, SZ_INT); const m_uint index = *(m_uint *)REG(-SZ_INT); const M_Object o = *(M_Object *)REG(-SZ_INT) = new_object(shred->info->mp, NULL, (Type)instr->m_val); @@ -142,11 +141,11 @@ static INSTR(UnionCtor) { } static OP_EMIT(opem_union_ctor) { - Exp_Call * call = (Exp_Call *)data; - const Type base = actual_type(emit->gwion, call->func->type); - const Instr instr = emit_add_instr(emit, UnionCtor); - instr->m_val = (m_uint)base; - instr->m_val2 = call->args->next->type->size; + Exp_Call *const call = (Exp_Call *)data; + const Type base = actual_type(emit->gwion, call->func->type); + const Instr instr = emit_add_instr(emit, UnionCtor); + instr->m_val = (m_uint)base; + instr->m_val2 = call->args->next->type->size; return GW_OK; } diff --git a/tests/union/none.gw b/tests/union/none.gw index 1bb4787a..3ee84d78 100644 --- a/tests/union/none.gw +++ b/tests/union/none.gw @@ -1 +1,2 @@ +#! [contains] right-side operand is non-mutable None => None; diff --git a/tests/union/option_check.gw b/tests/union/option_check.gw index 81ed9990..b9a7d59f 100644 --- a/tests/union/option_check.gw +++ b/tests/union/option_check.gw @@ -1,9 +1,6 @@ -#! [contains] 12 +#! [contains] val: 12 var int? i; -<<< 12 => i.val >>>; +12 => i.val; if(i.is(val)) - <<< i.val >>>; -#!<<< None => i.none >>>; -#!if(i.is(none)) -#! <<< "option unset" >>>; + <<< "val: ${i.val}" >>>; diff --git a/tests/union/union.gw b/tests/union/union.gw index 88d47c27..14c31e28 100644 --- a/tests/union/union.gw +++ b/tests/union/union.gw @@ -1,10 +1,12 @@ +#! [contains] 2.4 union U { int i; float f; } -var U u; +U(i, 1) => var U u; <<< u.i >>>; +2.4 => u.f; <<< u.f >>>;