github.com/traefik/yaegi@v0.15.1/_test/issue-1465.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  func SomeFunc[T int | string](defaultValue T) T {
     8  	switch v := any(&defaultValue).(type) {
     9  	case *string:
    10  		*v = *v + " abc"
    11  	case *int:
    12  		*v -= 234
    13  	}
    14  	return defaultValue
    15  }
    16  
    17  func main() {
    18  	fmt.Println(SomeFunc("test"))
    19  	fmt.Println(SomeFunc(1234))
    20  }
    21  
    22  // Output:
    23  // test abc
    24  // 1000