From 2034dcb4ed04bf89da7750a74c4a880f22a2f0e3 Mon Sep 17 00:00:00 2001 From: yuyi Date: Tue, 17 Jan 2023 18:12:54 +0800 Subject: [PATCH] ast: fix const values defined in the wrong order (#17002) --- vlib/v/ast/table.v | 3 +++ vlib/v/slow_tests/inout/printing_const_array.out | 9 +++++++++ vlib/v/slow_tests/inout/printing_const_array.vv | 13 +++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 vlib/v/slow_tests/inout/printing_const_array.out create mode 100644 vlib/v/slow_tests/inout/printing_const_array.vv diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index 597df7dae..ec336588b 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -2284,6 +2284,9 @@ pub fn (t &Table) dependent_names_in_expr(expr Expr) []string { for elem_expr in expr.exprs { names << t.dependent_names_in_expr(elem_expr) } + names << t.dependent_names_in_expr(expr.len_expr) + names << t.dependent_names_in_expr(expr.cap_expr) + names << t.dependent_names_in_expr(expr.default_expr) } CallExpr { for arg in expr.args { diff --git a/vlib/v/slow_tests/inout/printing_const_array.out b/vlib/v/slow_tests/inout/printing_const_array.out new file mode 100644 index 000000000..575de7b14 --- /dev/null +++ b/vlib/v/slow_tests/inout/printing_const_array.out @@ -0,0 +1,9 @@ +[Info{ + val: 'No data' +}, Info{ + val: 'Data tag 1' +}, Info{ + val: 'Data tag 2' +}, Info{ + val: 'No data' +}] diff --git a/vlib/v/slow_tests/inout/printing_const_array.vv b/vlib/v/slow_tests/inout/printing_const_array.vv new file mode 100644 index 000000000..6e9dcf4e2 --- /dev/null +++ b/vlib/v/slow_tests/inout/printing_const_array.vv @@ -0,0 +1,13 @@ +const ( + dat = 'Data tag ,No data'.split(',') + dd = []Info{len: 4, init: Info{if it in tag { dat[0] + it.str() } else { dat[1] }}} + tag = [1, 2] +) + +struct Info { + val string +} + +fn main() { + println(dd) +} -- 2.39.5