gnolang / gno

Gno: An interpreted, stack-based Go virtual machine to build succinct and composable apps + Gno.land: a blockchain for timeless code and fair open-source
https://gno.land/
Other
841 stars 342 forks source link

bug(gnovm): incorrect type comparison #2386

Open moul opened 1 week ago

moul commented 1 week ago

CleanShot 2024-06-18 at 16 59 30

https://go.dev/play/p/-y5gRjR9erA https://play.gno.land/p/B9WLR_AsqYY


In GnoVM, type aliases with the same value are considered equal, while in Go, they are considered different without explicit casting. This leads to inconsistent behavior between Gno and Go.

Example

The following code returns false, false, false in Go, but true, false, false in Gno:

package main

import "fmt"

func check(v1, v2 interface{}) bool {
    return v1 == v2
}

func main() {
    type t1 int
    type t2 int
    v1 := t1(1)
    v2 := t2(1)
    v3 := t2(3)

    fmt.Println("v1, v2", v1, v2, check(v1, v2))
    fmt.Println("v1, v3", v1, v3, check(v1, v3))
    fmt.Println("v2, v3", v2, v3, check(v2, v3))
}
thehowl commented 1 week ago

cc @ltzmaxwell is this fixed by #1426?

deelawn commented 1 week ago

This is not fixed by #1426

ltzmaxwell commented 1 week ago

this should be fixed in #1890. similar context with https://github.com/gnolang/gno/issues/1376.