wasmerio / wasmer-go

🐹🕸️ WebAssembly runtime for Go
https://pkg.go.dev/github.com/wasmerio/wasmer-go
MIT License
2.84k stars 161 forks source link

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

Open jimjbrettj opened 1 year ago

jimjbrettj commented 1 year ago

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 https://github.com/wasmerio/wasmer-go/blob/ca60a4524acf4fc518ced3bfd818d960804a0bee/wasmer/value.go#L207

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.