From bb65c5ce2b92e89940678117900c3e0d8427d371 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sat, 11 Jun 2022 16:25:34 +0200 Subject: compiler: add support for type parameters (aka generics) ...that was surprisingly easy. --- testdata/generics.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 testdata/generics.go (limited to 'testdata/generics.go') diff --git a/testdata/generics.go b/testdata/generics.go new file mode 100644 index 000000000..9f1a19708 --- /dev/null +++ b/testdata/generics.go @@ -0,0 +1,14 @@ +package main + +func main() { + println("add:", Add(3, 5)) + println("add:", Add(int8(3), 5)) +} + +type Integer interface { + int | int8 | int16 | int32 | int64 +} + +func Add[T Integer](a, b T) T { + return a + b +} -- cgit v1.2.3