gopherdata / gopherdata/gophernotes
Error `cannot convert type <*main.b> to interface <error>` on valid Go code
- 主要語言
- 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 還沒有評估資料。