diff options
author | Ayke van Laethem <[email protected]> | 2022-06-11 16:25:34 +0200 |
---|---|---|
committer | Ron Evans <[email protected]> | 2022-06-11 20:41:16 +0200 |
commit | bb65c5ce2b92e89940678117900c3e0d8427d371 (patch) | |
tree | 8fe1b9a919c2ad4fce56ed16ec3f4f0d639412a8 /testdata/generics.go | |
parent | 283fed16a5c112b1e6682b08ed61552059c90ccc (diff) | |
download | tinygo-bb65c5ce2b92e89940678117900c3e0d8427d371.tar.gz tinygo-bb65c5ce2b92e89940678117900c3e0d8427d371.zip |
compiler: add support for type parameters (aka generics)
...that was surprisingly easy.
Diffstat (limited to 'testdata/generics.go')
-rw-r--r-- | testdata/generics.go | 14 |
1 files changed, 14 insertions, 0 deletions
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 +} |