Cannot use interface methods when returned through function returning `[]Interface` type
- 主要语言
- Go
- 星标
- 2.3k
- 派生
- 136
- 平均合并
- 14 分钟
- 30 天内合并 PR
- 2
描述
Reproduction steps:
1. Run commands:
```
mkdir dum
cd dum
go mod init dummy.com/dum
mkdir hello
```
2. Create file named `hello/hello.go` with following contents:
```go
package hello
type Example interface {
Sample() int
}
type ExampleImpl struct {
sample int
}
func (example *ExampleImpl) Sample() int {
return example.sample
}
func Hello() []Example {
return []Example{&ExampleImpl{sample: 123}, &ExampleImpl{sample: 321}}
}
```
3. Build with `gopy`:
```
gopy build -output=out dummy.com/dum/hello
```
4. Run the following Python code:
```pycon
>>> from out import hello
>>> output = hello.Hello()
>>> output[0].Sample()
panic: interface conversion: *hello.Example is not hello.Example: missing method Sample
goroutine 17 [running, locked to thread]:
main.hello_Example_Sample(0x2)
/tmp/dum/out/hello.go:1230 +0xf9
zsh: IOT instruction (core dumped) python
```
贡献指南
这个仓库没有索引到贡献指南
调研方向
使用报告中的命令复现该问题,然后检查生成的 out/hello.go 中 hello_Example_Sample 附近的内容以及 hello.Hello 的 wrapper。验证 hello.Hello 返回的接口可以在两个元素上调用 Sample 而不会发生 panic,并返回 123 和 321。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- go, python
- 领域
- tooling
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100