From 826f10c35ba31eb432445c071c578db7c617b2f9 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 11 Mar 2026 15:48:30 +0300 Subject: [PATCH] wasm: backend indexing issue (fixes #21997) --- vlib/v/gen/wasm/gen.v | 3 +++ vlib/v/gen/wasm/tests/arrays.vv | 19 +++++++++++++++++++ vlib/v/gen/wasm/tests/arrays.vv.out | 6 +++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/vlib/v/gen/wasm/gen.v b/vlib/v/gen/wasm/gen.v index 9467190b5..f7338cbbc 100644 --- a/vlib/v/gen/wasm/gen.v +++ b/vlib/v/gen/wasm/gen.v @@ -966,7 +966,10 @@ pub fn (mut g Gen) expr(node ast.Expr, expected ast.Type) { size, _ := g.pool.type_size(typ) + old_needs_address := g.needs_address + g.needs_address = false g.expr(node.index, ast.int_type) + g.needs_address = old_needs_address if !direct_array_access { g.is_leaf_function = false // calls panic() diff --git a/vlib/v/gen/wasm/tests/arrays.vv b/vlib/v/gen/wasm/tests/arrays.vv index 35c9aa016..d43543c6f 100644 --- a/vlib/v/gen/wasm/tests/arrays.vv +++ b/vlib/v/gen/wasm/tests/arrays.vv @@ -37,6 +37,12 @@ struct AA { a [10]&int } +struct IndexedWrite { +mut: + idx u8 + frame [4]u8 +} + fn test_stuff() &int { a := AA{} @@ -46,6 +52,16 @@ fn test_stuff() &int { return b } +fn selector_index_assign() { + mut app := IndexedWrite{} + app.idx = 1 + app.frame[app.idx] = 123 + + println(app.frame[0]) + println(app.frame[1]) + println(app.frame[app.idx]) +} + fn main() { println('--- static_arrays()') a, b, c := static_arrays() @@ -64,4 +80,7 @@ fn main() { println('--- test_stuff()') v := test_stuff() println(v) + + println('--- selector_index_assign()') + selector_index_assign() } diff --git a/vlib/v/gen/wasm/tests/arrays.vv.out b/vlib/v/gen/wasm/tests/arrays.vv.out index a710bbc41..f020c11b5 100644 --- a/vlib/v/gen/wasm/tests/arrays.vv.out +++ b/vlib/v/gen/wasm/tests/arrays.vv.out @@ -11,4 +11,8 @@ 10 10 --- test_stuff() -0 \ No newline at end of file +0 +--- selector_index_assign() +0 +123 +123 -- 2.39.5