traefik / yaegi

Yaegi is Another Elegant Go Interpreter
https://pkg.go.dev/github.com/traefik/yaegi
Apache License 2.0
7.1k stars 351 forks source link

interface conversion: interface {} is *string, not interp.valueInterface #1465

Closed michaelboke closed 2 years ago

michaelboke commented 2 years ago

The following program sample.go triggers an unexpected result

package main

import (
    "fmt"
)

func SomeFunc[T int | string](defaultValue T) T {
    switch v := any(&defaultValue).(type) {
    case *string:
        *v = *v + " abc"
    case *int:
        *v -= 234
    }
    return defaultValue
}

func main() {
    fmt.Println(SomeFunc("test"))
    fmt.Println(SomeFunc(1234))
}

Expected result

test abc
1000

Got

main.go:8:2: panic
main.go:18:2: panic
run: interface conversion: interface {} is *string, not interp.valueInterface

Yaegi Version

0.14.2

Additional Notes

I stumbled on this error while I was creating some bridge wrappers for some external generic methods.

Could reduce it to this example, hope someone can help me solve this one. As i do have a hard time understanding the internals of the interpreter that doing the cast at some point

/github.com/traefik/yaegi@v0.14.2/interp/run.go:2999

vi := v.Interface().(valueInterface)