From 1ca7157b8142b0d9c4bde125bbee1d9aa3098921 Mon Sep 17 00:00:00 2001 From: "ChAoS_UnItY (Kyle Lin)" Date: Fri, 14 Mar 2025 21:45:01 +0800 Subject: [PATCH] markused: fix markused behavior on array / map index getter / setter / slice (#23931) --- vlib/v/markused/walker.v | 13 +++++++++++++ vlib/v/tests/skip_unused/array_index.run.out | 1 + .../skip_unused/array_index.skip_unused.run.out | 1 + vlib/v/tests/skip_unused/array_index.vv | 3 +++ 4 files changed, 18 insertions(+) create mode 100644 vlib/v/tests/skip_unused/array_index.run.out create mode 100644 vlib/v/tests/skip_unused/array_index.skip_unused.run.out create mode 100644 vlib/v/tests/skip_unused/array_index.vv diff --git a/vlib/v/markused/walker.v b/vlib/v/markused/walker.v index b9d67c9e2..f67b73888 100644 --- a/vlib/v/markused/walker.v +++ b/vlib/v/markused/walker.v @@ -364,11 +364,24 @@ fn (mut w Walker) expr(node_ ast.Expr) { } sym := w.table.final_sym(node.left_type) if sym.kind == .map { + if node.is_setter { + w.mark_builtin_map_method_as_used('set') + } else { + w.mark_builtin_map_method_as_used('get') + } + w.features.used_maps++ } else if sym.kind == .array { + if node.is_setter { + w.mark_builtin_array_method_as_used('set') + } else { + w.mark_builtin_array_method_as_used('get') + } + w.features.used_arrays++ } else if sym.kind == .string { if node.index is ast.RangeExpr { + w.mark_builtin_array_method_as_used('slice') w.features.range_index = true } } diff --git a/vlib/v/tests/skip_unused/array_index.run.out b/vlib/v/tests/skip_unused/array_index.run.out new file mode 100644 index 000000000..84e8f8061 --- /dev/null +++ b/vlib/v/tests/skip_unused/array_index.run.out @@ -0,0 +1 @@ +[17, 34, 51, 68, 238] diff --git a/vlib/v/tests/skip_unused/array_index.skip_unused.run.out b/vlib/v/tests/skip_unused/array_index.skip_unused.run.out new file mode 100644 index 000000000..84e8f8061 --- /dev/null +++ b/vlib/v/tests/skip_unused/array_index.skip_unused.run.out @@ -0,0 +1 @@ +[17, 34, 51, 68, 238] diff --git a/vlib/v/tests/skip_unused/array_index.vv b/vlib/v/tests/skip_unused/array_index.vv new file mode 100644 index 000000000..aa7c7a467 --- /dev/null +++ b/vlib/v/tests/skip_unused/array_index.vv @@ -0,0 +1,3 @@ +fn main() { + println('0x11223344ee'.u8_array()) +} -- 2.39.5