mirror of
https://github.com/hanzoai/yaegi.git
synced 2026-10-01 00:49:47 +00:00
In case of interface values, make sure that the concrete type is preserved during type inference. Fixes #1466.
25 lines
315 B
Go
25 lines
315 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
func SomeFunc(defaultValue interface{}) interface{} {
|
|
switch v := defaultValue.(type) {
|
|
case string:
|
|
return v + " abc"
|
|
case int:
|
|
return v - 234
|
|
}
|
|
panic("whoops")
|
|
}
|
|
|
|
func main() {
|
|
fmt.Println(SomeFunc(1234))
|
|
fmt.Println(SomeFunc("test"))
|
|
}
|
|
|
|
// Output:
|
|
// 1000
|
|
// test abc
|