github.com/traefik/yaegi@v0.15.1/_test/switch14.go (about)

     1  package main
     2  
     3  import "fmt"
     4  
     5  type fii interface {
     6  	Hello()
     7  }
     8  
     9  type Boo struct {
    10  	Name string
    11  }
    12  
    13  type Bir struct {
    14  	Boo
    15  }
    16  
    17  type Bar struct{}
    18  
    19  func (b Bar) Hello() { fmt.Println("b:", b) }
    20  
    21  func (b Boo) Hello() {
    22  	fmt.Println("Hello", b)
    23  	fmt.Println(b.Name)
    24  }
    25  
    26  func inCall(foo fii) {
    27  	fmt.Println("inCall")
    28  	switch a := foo.(type) {
    29  	case Boo:
    30  		a.Hello()
    31  	default:
    32  		fmt.Println("a:", a)
    33  	}
    34  }
    35  
    36  func main() {
    37  	boo := Bir{Boo{"foo"}}
    38  	inCall(boo)
    39  	inCall(Bar{})
    40  }
    41  
    42  // Output:
    43  // inCall
    44  // a: {{foo}}
    45  // inCall
    46  // a: {}