...

Text file src/go/doc/testdata/examples/generic_constraints.golden

Documentation: go/doc/testdata/examples

     1-- .Play --
     2package main
     3
     4import (
     5	"fmt"
     6)
     7
     8func main() {
     9	fmt.Println("hello")
    10}
    11-- Generic.Play --
    12package main
    13
    14import (
    15	"fmt"
    16	"time"
    17)
    18
    19type C1 interface {
    20	string | int
    21}
    22
    23type C2 interface {
    24	M(time.Time)
    25}
    26
    27type G[T C1] int
    28
    29func g[T C2](x T) {}
    30
    31type Tm int
    32
    33func (Tm) M(time.Time) {}
    34
    35func main() {
    36	var x G[string]
    37	g(Tm(3))
    38	fmt.Println(x)
    39}

View as plain text