go-python / go-python/gopy

Cannot use interface methods when returned through function returning `[]Interface` type

オープン
#357 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る
主要言語
Go
スター
2.3k
フォーク
136
平均マージ
14分
マージ済み PR(30日)
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
```

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。