Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gnovm: discrepancy between right-hand-side type coercion of interface against nil #3735

Closed
odeke-em opened this issue Feb 12, 2025 · 3 comments
Labels
🐞 bug Something isn't working

Comments

@odeke-em
Copy link
Contributor

Noticed while I was studying the typechecker and hunting for bugs that'll cause crashes in the GnoVM, see this perfectly correctly Go code

package main
import "io"
func main() {
   _ = (io.Writer)(nil)
}

which successfully passes in Go per https://go.dev/play/p/EQzIyLTYMsi

but fails in Gno per https://play.gno.land/p/7_UM8jIkMOs with

panic:invalid operation, nil can not be compared to <nil [recovered]
       panic:main//src/package.gno:4:4: invalid operation, nil can not be compared to <nil>:
--- preprocess stack ---
stack 2: func main() { _<VPBlock(0,0)> = (const (undefined)) }
stack 1: file{ package main; import io io; func main() { _<VPBlock(0,0)> = (const (undefined)) } }
stack 0: package(main)
------------------------

goroutine runnin]:
github.com/gnolang/gno/gnovm/pkg/gnolang.doRecove0x2cc960,0x,0x2,0x4e010,0x27b17a)
       /home/runner/_work/studio/studio/gno/gnovm/pkg/gnolang/preprocess.g37 0x24
pani0xc474,0x2f66a7)
       /home/runner/_work/_tool/go/1.22.4/x64/src/runtime/panic.g77 0x1a
github.com/gnolang/gno/gnovm/pkg/gnolang.checkAssignableT0x,0x,0x,0x,0x)
       /home/runner/_work/studio/studio/gno/gnovm/pkg/gnolang/type_check.g29 0x381
github.com/gnolang/gno/gnovm/pkg/gnolang.assertAssignableT0x,0x,0x,0x,0x)

Comparisons

If however we get this code, this passes alright in Gno per https://play.gno.land/p/55Ch0BOwLYO

import "io"

type ts int

func (t *ts) Write(b []byte) (int, error) {
  return len(b), nil
}

func main() {
  var t *ts = nil
  _ = (io.Writer)(t)
}

and then also

  _ = (io.Writer)(new(ts))
  var _ io.Writer = nil

compiles and doesn't panic at runtime

@odeke-em
Copy link
Contributor Author

Hmmm it fails on the Gno playground but not locally with gno run main.go. It would be nice if the playground had a way to use the latest code on Gno master otherwise we have divergences that cause false alarms: kindly @n2p5 @ltzmaxwell

@leohhhn
Copy link
Contributor

leohhhn commented Feb 13, 2025

@odeke-em

Yep, the playground is using the test5 Gno binary commit. For now, please use the master version binary locally to test things.

We discussed adding a master release to the playground, but it requires a bit of orchestration. I'll see with the team again if it's possible (I would also like to have it)

@odeke-em
Copy link
Contributor Author

Thanks @leohhhn!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
Development

No branches or pull requests

2 participants