From 6348e581ded7db8661171a8d8d4336ee1ca8a2d9 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Thu, 9 Jan 2025 05:40:10 -0300 Subject: [PATCH] cgen: fix codegen for array fixed comparison on MatchExpr (fix #23403) (#23415) --- vlib/v/gen/c/match.v | 3 +++ vlib/v/tests/match_array_fixed_test.v | 14 ++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 vlib/v/tests/match_array_fixed_test.v diff --git a/vlib/v/gen/c/match.v b/vlib/v/gen/c/match.v index 5c56cb87d..babaaccb6 100644 --- a/vlib/v/gen/c/match.v +++ b/vlib/v/gen/c/match.v @@ -482,6 +482,9 @@ fn (mut g Gen) match_expr_classic(node ast.MatchExpr, is_expr bool, cond_var str .array_fixed { ptr_typ := g.equality_fn(node.cond_type) g.write('${ptr_typ}_arr_eq(${cond_var}, ') + if expr is ast.ArrayInit { + g.write('(${g.styp(node.cond_type)})') + } g.expr(expr) g.write(')') } diff --git a/vlib/v/tests/match_array_fixed_test.v b/vlib/v/tests/match_array_fixed_test.v new file mode 100644 index 000000000..933412339 --- /dev/null +++ b/vlib/v/tests/match_array_fixed_test.v @@ -0,0 +1,14 @@ +fn test_main() { + on_event() +} + +fn on_event() { + match [0, 0]! { + [0, 1]! { + assert false + } + else { + assert true + } + } +} -- 2.39.5