From 025150dec4502e849b11d3ed962b04973c270614 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Mon, 9 Dec 2024 12:56:44 -0300 Subject: [PATCH] markused: fix short program with array push only (fix #23110) (#23112) --- vlib/v/checker/infix.v | 4 ++++ vlib/v/tests/skip_unused/array_push.run.out | 0 .../tests/skip_unused/array_push.skip_unused.run.out | 0 vlib/v/tests/skip_unused/array_push.vv | 11 +++++++++++ 4 files changed, 15 insertions(+) create mode 100644 vlib/v/tests/skip_unused/array_push.run.out create mode 100644 vlib/v/tests/skip_unused/array_push.skip_unused.run.out create mode 100644 vlib/v/tests/skip_unused/array_push.vv diff --git a/vlib/v/checker/infix.v b/vlib/v/checker/infix.v index f4e27fa70..8e63a122d 100644 --- a/vlib/v/checker/infix.v +++ b/vlib/v/checker/infix.v @@ -44,6 +44,10 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type { } // `arr << if n > 0 { 10 } else { 11 }` set the right c.expected_type if node.op == .left_shift && c.table.sym(left_type).kind == .array { + if c.pref.skip_unused && !c.is_builtin_mod && c.mod != 'strings' { + c.table.used_features.index = true + c.table.used_features.arr_init = true + } if mut node.right is ast.IfExpr { if node.right.is_expr && node.right.branches.len > 0 { mut last_stmt := node.right.branches[0].stmts.last() diff --git a/vlib/v/tests/skip_unused/array_push.run.out b/vlib/v/tests/skip_unused/array_push.run.out new file mode 100644 index 000000000..e69de29bb diff --git a/vlib/v/tests/skip_unused/array_push.skip_unused.run.out b/vlib/v/tests/skip_unused/array_push.skip_unused.run.out new file mode 100644 index 000000000..e69de29bb diff --git a/vlib/v/tests/skip_unused/array_push.vv b/vlib/v/tests/skip_unused/array_push.vv new file mode 100644 index 000000000..1dcb15d0f --- /dev/null +++ b/vlib/v/tests/skip_unused/array_push.vv @@ -0,0 +1,11 @@ +module main + +struct GameObject { +mut: + children []&GameObject +} + +fn main() { + mut v1 := &GameObject{} + v1.children << v1 +} -- 2.39.5