wasmerio / wasmer-go

🐹🕸️ WebAssembly runtime for Go

Home Page:https://pkg.go.dev/github.com/wasmerio/wasmer-go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why does converting to I32 with a uint32 value panic if the I32 type is sign agnostic?

jimjbrettj opened this issue · comments

commented

Summary

It is my understanding that the I32 type is sign agnostic, meaning it should be able to handle both int32 and uint32 types. However this is not how wasmer appears to handle it. See this code snippet:

`case I32:

	output.kind = kind.inner()
	var of = (*int32)(unsafe.Pointer(&output.of))
	switch value.(type) {
	case int8:
		*of = int32(value.(int8))
	case uint8:
		*of = int32(value.(uint8))
	case int16:
		*of = int32(value.(int16))
	case uint16:
		*of = int32(value.(uint16))
	case int32:
		*of = value.(int32)
	case int:
		*of = int32(value.(int))
	case uint:
		*of = int32(value.(uint))
	default:
		return output, newErrorWith("i32")
	}`

from

func fromGoValue(value interface{}, kind ValueKind) (C.wasm_val_t, error) {

I need to pass in uint32 values, and I had expected that they should be encompased in the I32 type, but my code panics. Am I misunderstanding something here or is this a bug?

Any help/guidance would be appreciated, thanks!

Additional details

Provide any additional details here.