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

     1  package main
     2  
     3  import "unsafe"
     4  
     5  type Coord interface {
     6  	int | float32
     7  }
     8  
     9  type Point[T Coord] struct {
    10  	X, Y T
    11  }
    12  
    13  func Add[T Coord](a, b Point[T]) Point[T] {
    14  	checkSize(unsafe.Alignof(a))
    15  	checkSize(unsafe.Sizeof(a))
    16  	return Point[T]{
    17  		X: a.X + b.X,
    18  		Y: a.Y + b.Y,
    19  	}
    20  }
    21  
    22  func main() {
    23  	var af, bf Point[float32]
    24  	Add(af, bf)
    25  
    26  	var ai, bi Point[int]
    27  	Add(ai, bi)
    28  }
    29  
    30  func checkSize(uintptr)