From 81b421bb5baedfbd0040b6c70381efcb9a8c3124 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sat, 11 Jan 2025 14:37:19 -0300 Subject: [PATCH] markused: fix `-skip-unused` on a short program, that prints array (fix #23436) (#23437) --- vlib/v/markused/markused.v | 3 +++ vlib/v/tests/skip_unused/call_arguments.run.out | 0 vlib/v/tests/skip_unused/call_arguments.skip_unused.run.out | 0 vlib/v/tests/skip_unused/call_arguments.vv | 4 ++++ 4 files changed, 7 insertions(+) create mode 100644 vlib/v/tests/skip_unused/call_arguments.run.out create mode 100644 vlib/v/tests/skip_unused/call_arguments.skip_unused.run.out create mode 100644 vlib/v/tests/skip_unused/call_arguments.vv diff --git a/vlib/v/markused/markused.v b/vlib/v/markused/markused.v index f1ba4b40c1f6b5..515b41016ea922 100644 --- a/vlib/v/markused/markused.v +++ b/vlib/v/markused/markused.v @@ -166,6 +166,9 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a builderptr_idx + '.write_rune', ] } + if !table.used_features.arr_init { + table.used_features.arr_init = table.used_features.print_types.keys().any(table.type_to_str(it).contains('[]')) + } if table.used_features.arr_init || table.used_features.comptime_for { include_panic_deps = true core_fns << '__new_array' diff --git a/vlib/v/tests/skip_unused/call_arguments.run.out b/vlib/v/tests/skip_unused/call_arguments.run.out new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/vlib/v/tests/skip_unused/call_arguments.skip_unused.run.out b/vlib/v/tests/skip_unused/call_arguments.skip_unused.run.out new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/vlib/v/tests/skip_unused/call_arguments.vv b/vlib/v/tests/skip_unused/call_arguments.vv new file mode 100644 index 00000000000000..ca687f27fbe9d0 --- /dev/null +++ b/vlib/v/tests/skip_unused/call_arguments.vv @@ -0,0 +1,4 @@ +fn main() { + args := arguments() + assert args.len > 0 +}