compiler: add support for type parameters (aka generics)

...that was surprisingly easy.
This commit is contained in:
Ayke van Laethem
2022-06-11 16:25:34 +02:00
committed by Ron Evans
parent 283fed16a5
commit bb65c5ce2b
11 changed files with 83 additions and 17 deletions
+14
View File
@@ -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
}
+2
View File
@@ -0,0 +1,2 @@
add: 8
add: 8