gopherdata / gophernotes

The Go kernel for Jupyter notebooks and nteract.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error `cannot convert type <*main.b> to interface <error>` on valid Go code

codemicro opened this issue · comments

commented

When attempting to run the following snippet of Go code in the latest version of gophernotes, v0.7.4, I get the following error:

import "fmt"

type b struct {}
func (*b) Error() string { return "hi" }

func main() {
        var e error
        e = &b{}

        fmt.Println(e)
}
repl.go:8:9: error compiling assignment: e = &b{}
	repl.go:8:9: cannot convert type <*main.b> to interface <error>: missing method  Error

However, running essentially the same snippet with a package main declaration at the top yields the correc output.

package main

import "fmt"

type b struct {}
func (*b) Error() string { return "hi" }

func main() {
        var e error
        e = &b{}

        fmt.Println(e)
}
> go run main.go 
hi

:)

This is really weird:
I can reproduce the issue with gophernotes, but running your snippet in gomacro works as expected.
And they use the same interpreter (I used exactly matching version).

I will try to better examine this issue in the next days

Unsure if this is remotely helpful, but I can confirm I'm hitting this issue as well, and able to reproduce it using the snippet above.

  • macOS Monterey
  • Gophernotes 0.7.5
  • Go 1.19.3
  • Python 3.10.5

Jupyter core at the following versions:

Selected Jupyter core packages...
IPython          : 8.6.0
ipykernel        : 6.16.2
ipywidgets       : not installed
jupyter_client   : 7.4.4
jupyter_core     : 4.11.2
jupyter_server   : 1.21.0
jupyterlab       : 3.5.0
nbclient         : 0.7.0
nbconvert        : 7.2.3
nbformat         : 5.7.0
notebook         : 6.5.2
qtconsole        : not installed
traitlets        : 5.5.0

Additionally, I can confirm that any interface methods seem to have difficulty resolving, not just error.

seems to be fixed in @latest version (not yet released with a formal version number)