gopherdata / gopherdata/gophernotes

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

未关闭
#246 3 条评论 1 个 reaction 已指派 1 人 已被 @cosmos72 认领 在 GitHub 查看
bug
主要语言
Go
星标
4k
派生
264
平均合并
7 天 21 小时
30 天内合并 PR
1

描述

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

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。