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
880 stars 364 forks source link

Clarify custom types support #2006

Open x1unix opened 5 months ago

x1unix commented 5 months ago

Description

In Go language, user is able to define a custom type on top of a built-in type.

For example:

type Set map[string]struct{}

func NewSet(items ...string) Set {
   ...
}

func (s Set) Has(key string) bool {
  _, ok := s[key]
 return ok
}

When I'm trying to use the same type, I get a following error:

Snippet

recovered: interface conversion: gnolang.Type is *gnolang.DeclaredType, not *gnolang.MapType
stack:
goroutine 60 [running]:
runtime/debug.Stack()
    /usr/local/go/src/runtime/debug/stack.go:24 +0x65
github.com/gnolang/gno/pkgs/sdk.(*BaseApp).runTx.func1()
    /opt/build/pkgs/sdk/baseapp.go:743 +0x2cd
panic({0xc60820, 0xc014450700})
    /usr/local/go/src/runtime/panic.go:884 +0x212

...

The same code but without custom map type works.

Looks like, Gno doesn't support this kind of stuff. I checked Go and Gno compat guide but it didn't mention this limitation.

Can you please update the compat doc?

deelawn commented 5 months ago

The problem mentioned here will be fixed by #1246