aboutsummaryrefslogtreecommitdiffhomepage
path: root/testdata/generics.go
blob: bc7e5145b4f8ba4143fb366019084a9e4b8c985b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main

import (
	"github.com/tinygo-org/tinygo/testdata/generics/testa"
	"github.com/tinygo-org/tinygo/testdata/generics/testb"
)

func main() {
	println("add:", Add(3, 5))
	println("add:", Add(int8(3), 5))

	var c C[int]
	c.F() // issue 2951

	SliceOp([]int(nil)) // issue 3002

	testa.Test()
	testb.Test()
}

type Integer interface {
	int | int8 | int16 | int32 | int64
}

func Add[T Integer](a, b T) T {
	return a + b
}

// Test for https://github.com/tinygo-org/tinygo/issues/2951
type C[V any] struct{}

func (c *C[V]) F() {}

// Test for https://github.com/tinygo-org/tinygo/issues/3002
func SliceOp[S ~[]E, E any](s S) {}