github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/testdata/generics.go (about)

     1  package main
     2  
     3  import (
     4  	"github.com/tinygo-org/tinygo/testdata/generics/testa"
     5  	"github.com/tinygo-org/tinygo/testdata/generics/testb"
     6  )
     7  
     8  func main() {
     9  	println("add:", Add(3, 5))
    10  	println("add:", Add(int8(3), 5))
    11  
    12  	var c C[int]
    13  	c.F() // issue 2951
    14  
    15  	SliceOp([]int(nil)) // issue 3002
    16  
    17  	testa.Test()
    18  	testb.Test()
    19  }
    20  
    21  type Integer interface {
    22  	int | int8 | int16 | int32 | int64
    23  }
    24  
    25  func Add[T Integer](a, b T) T {
    26  	return a + b
    27  }
    28  
    29  // Test for https://github.com/tinygo-org/tinygo/issues/2951
    30  type C[V any] struct{}
    31  
    32  func (c *C[V]) F() {}
    33  
    34  // Test for https://github.com/tinygo-org/tinygo/issues/3002
    35  func SliceOp[S ~[]E, E any](s S) {}