github.com/traefik/yaegi@v0.15.1/_test/switch17.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  		fmt.Println("type Boo")
    31  		a.Hello()
    32  	case Bir:
    33  		fmt.Println("type Bir")
    34  		a.Hello()
    35  	default:
    36  		fmt.Println("a:", a)
    37  	}
    38  }
    39  
    40  func main() {
    41  	boo := Bir{Boo{"foo"}}
    42  	inCall(boo)
    43  	inCall(Bar{})
    44  }
    45  
    46  // Output:
    47  // inCall
    48  // type Bir
    49  // Hello {foo}
    50  // foo
    51  // inCall
    52  // a: {}