From: Brendan Hansen Date: Tue, 6 Jul 2021 23:20:00 +0000 (-0500) Subject: bugfix with if-expressions X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=a810acbdadd06223a79de6681181523b0258fa0d;p=onyx.git bugfix with if-expressions --- diff --git a/bin/onyx b/bin/onyx index c27bdd35..b37e2794 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/src/onyxwasm.c b/src/onyxwasm.c index 7393bd32..8f5fbe82 100644 --- a/src/onyxwasm.c +++ b/src/onyxwasm.c @@ -2257,6 +2257,7 @@ EMIT_FUNC(if_expression, AstIfExpression* if_expr) { if (!result_is_local) emit_store_instruction(mod, &code, if_expr->type, offset); else WIL(WI_LOCAL_SET, result_local); + offset = 0; WI(WI_ELSE); if (!result_is_local) emit_local_location(mod, &code, (AstLocal *) if_expr, &offset); @@ -2267,6 +2268,7 @@ EMIT_FUNC(if_expression, AstIfExpression* if_expr) { emit_leave_structured_block(mod, &code); + offset = 0; if (!result_is_local) { emit_local_location(mod, &code, (AstLocal *) if_expr, &offset); emit_load_instruction(mod, &code, if_expr->type, offset); diff --git a/tests/if_expressions b/tests/if_expressions index 462d7752..28833aff 100644 --- a/tests/if_expressions +++ b/tests/if_expressions @@ -1,3 +1,4 @@ 5678.0000 True 20 +V2 { x = 10.0000, y = 20.0000 } diff --git a/tests/if_expressions.onyx b/tests/if_expressions.onyx index 3388df86..050a26e1 100644 --- a/tests/if_expressions.onyx +++ b/tests/if_expressions.onyx @@ -12,6 +12,8 @@ new_max :: (a: $T, b: T) -> T { return a if a > b else b; } +V2 :: struct { x, y: f32; } + main :: (args: [] cstr) { condition := 12 > 34; @@ -22,4 +24,7 @@ main :: (args: [] cstr) { println("True" if x > 5000 else "False" if false else "REALLY FALSE"); println(new_max(10, 20)); + + v: V2 = (.{ 10, 20 }) if true else .{ 30, 40 }; + printf("{}\n", v); } \ No newline at end of file