mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-04 11:07:46 +00:00
70c52ef1b4
Without this change, the compiler would probably have worked just fine but the generated types would look odd. You can see in the test case that it now doesn't use `main.Point` but rather the correct `main.Poin[float32]` etc.
25 lines
288 B
Go
25 lines
288 B
Go
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)
|
|
|
|
var ai, bi Point[int]
|
|
Add(ai, bi)
|
|
}
|