From 3dfd06be79feb3a7c5908f255cad2fd654998593 Mon Sep 17 00:00:00 2001 From: JMD <56417208+StunxFS@users.noreply.github.com> Date: Wed, 22 Oct 2025 07:28:32 -0400 Subject: [PATCH] checker: fix type inference, when pushing an empty array to a 2D array (fix #23854) (#25508) --- vlib/v/checker/infix.v | 7 +++++++ .../builtin_arrays/array_2d_append_empty_array_test.v | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100644 vlib/v/tests/builtin_arrays/array_2d_append_empty_array_test.v diff --git a/vlib/v/checker/infix.v b/vlib/v/checker/infix.v index 6f354c2f5..3173441ff 100644 --- a/vlib/v/checker/infix.v +++ b/vlib/v/checker/infix.v @@ -71,6 +71,13 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type { } } } + } else if mut node.right is ast.ArrayInit { + if node.right.exprs.len == 0 && node.right.elem_type == ast.void_type { + // handle arr << [] where [] is empty + info := c.table.sym(left_type).array_info() + node.right.elem_type = info.elem_type + c.expected_type = info.elem_type + } } } mut right_type := c.expr(mut node.right) diff --git a/vlib/v/tests/builtin_arrays/array_2d_append_empty_array_test.v b/vlib/v/tests/builtin_arrays/array_2d_append_empty_array_test.v new file mode 100644 index 000000000..4fd2e52d9 --- /dev/null +++ b/vlib/v/tests/builtin_arrays/array_2d_append_empty_array_test.v @@ -0,0 +1,7 @@ +fn test_array_2d_append_empty_array() { + mut b := [][]int{} + b << [1, 2, 3] + b << [] + assert b[0][0] == 1 + assert b[1] == [] +} -- 2.39.5