go-python / go-python/gopy

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

Abierto
#357 0 comentarios 1 reacción 0 asignados Ver en GitHub
Lenguaje dominante
Go
Estrellas
2.3k
Forks
136
Merge medio
14 min
PR fusionados (30 d)
2

Descripción

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

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.