v icon indicating copy to clipboard operation
v copied to clipboard

unexpected key and value in map foreach

Open Krchi opened this issue 5 months ago • 0 comments

Describe the bug

v/gen/wasm/mem.v:815 pub fn (mut g Gen) make_vinit()

		for idx, gv in g.global_vars {
			println('`$idx` $gv')
			if init := gv.init {
				g.set_with_expr(init, gv.v)
			}
		}

I add println before use it, and print out the text below, g.global_vars does not have an empty str key

...
...
...
`main.t_mask1` wasm.Global{
    init: Option(value)
    v: wasm.Var{
        name: 'main.t_mask1'
        typ: ast.Type(0x8 = 8)
        idx:         wasm.LocalIndex(0)
        is_address: false
        is_global: true
        g_idx:         wasm.GlobalIndex(5)
        offset: 0
    }
}
`` wasm.Global{
    init: Option([unhandled expr type unknown v.ast.Expr])
    v: wasm.Var{
        name: ''
        typ: ast.Type(0x0 = 0)
        idx:         wasm.LocalIndex(0)
        is_address: false
        is_global: false
        g_idx:         wasm.GlobalIndex(0)
        offset: 0
    }
}

first, unexpected key and value should not happen, and then, the wrong value gv.init seem like none, cannot set to init

Reproduction Steps

  1. code
module main

const value = 53
const t_mask1 = value
const t_mask2 = value
const t_mask3 = value
const t_mask4 = value
const t_mask5 = value

fn main() {
	println(t_mask1)
	println(t_mask2)
	println(t_mask3)
	println(t_mask4)
	println(t_mask5)
}
  1. command
v -b wasm -g main.v

Expected Behavior

compile the code

Current Behavior

DESKTOP-D5EJCFL% v -b wasm -g main.v wasm error: wasm.expr(): unhandled node: unknown v.ast.Expr

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.12

Environment details (OS name and version, etc.)

windows and wsl both have the problem

[!NOTE] You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote. Other reactions and those to comments will not be taken into account.

Krchi avatar Nov 13 '25 07:11 Krchi