mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-12 15:03:41 +00:00
compiler: add generics test case
This test case shows a few bugs, that I will fix in subsequent patches.
This commit is contained in:
committed by
Ron Evans
parent
58072a5167
commit
408855da14
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
type Coord interface {
|
||||
int | float32
|
||||
}
|
||||
|
||||
type Point[T Coord] struct {
|
||||
X, Y T
|
||||
}
|
||||
|
||||
func Add[T Coord](a, b Point[T]) Point[T] {
|
||||
return Point[T]{
|
||||
X: a.X + b.X,
|
||||
Y: a.Y + b.Y,
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
var af, bf Point[float32]
|
||||
Add(af, bf)
|
||||
}
|
||||
Reference in New Issue
Block a user