mirror of
https://github.com/hanzoai/yaegi.git
synced 2026-10-01 00:49:47 +00:00
Fixes #1315. With this PR, the package gopkg.in/yaml.v3 works in yaegi (fixes #1296).
33 lines
326 B
Go
33 lines
326 B
Go
package main
|
|
|
|
type Intf interface {
|
|
M()
|
|
}
|
|
|
|
type T struct {
|
|
s string
|
|
}
|
|
|
|
func (t *T) M() { println("in M") }
|
|
|
|
func f(i interface{}) {
|
|
switch j := i.(type) {
|
|
case Intf:
|
|
j.M()
|
|
default:
|
|
println("default")
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
var i Intf
|
|
var k interface{} = 1
|
|
i = &T{"hello"}
|
|
f(i)
|
|
f(k)
|
|
}
|
|
|
|
// Output:
|
|
// in M
|
|
// default
|