gophernotes icon indicating copy to clipboard operation
gophernotes copied to clipboard

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

Open codemicro opened this issue 3 years ago • 3 comments

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

:)

codemicro avatar Feb 11 '22 16:02 codemicro

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

cosmos72 avatar Feb 11 '22 17:02 cosmos72

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.

jgoldschrafe avatar Dec 21 '22 16:12 jgoldschrafe

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

cosmos72 avatar Mar 28 '24 20:03 cosmos72