From f1772370373e1bcb214ff9977d5d5b7382984fb3 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sun, 6 Jul 2025 02:33:13 -0300 Subject: [PATCH] cgen: fix const indexexpr dep (fix #24850) (#24851) --- vlib/v/ast/table.v | 3 +++ vlib/v/tests/consts/const_indexexpr_dep_test.v | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 vlib/v/tests/consts/const_indexexpr_dep_test.v diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index 55e67b920..8fd18525c 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -2557,6 +2557,9 @@ pub fn (t &Table) dependent_names_in_expr(expr Expr) []string { names << util.no_dots(expr.name) } } + IndexExpr { + names << t.dependent_names_in_expr(expr.left) + } IfExpr { for branch in expr.branches { names << t.dependent_names_in_expr(branch.cond) diff --git a/vlib/v/tests/consts/const_indexexpr_dep_test.v b/vlib/v/tests/consts/const_indexexpr_dep_test.v new file mode 100644 index 000000000..cfd35e99b --- /dev/null +++ b/vlib/v/tests/consts/const_indexexpr_dep_test.v @@ -0,0 +1,7 @@ +const array1 = [1] +const array2 = [array1] +const array3 = array2[0] + +fn test_main() { + assert array3 == array1 +} -- 2.39.5