gopherdata / gopherdata/gophernotes

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

Offen
#246 3 Kommentare 1 Reaktion 1 zugewiesene Person Beansprucht von @cosmos72 Auf GitHub ansehen
bug
Vorherrschende Sprache
Go
Sterne
4k
Forks
264
Ø Merge
7 T. 21 Std.
Gemergte PRs (30 T.)
1

Beschreibung

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

```go
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 : missing method Error
```

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

```go
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
```
:)

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.