mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 19:43:44 +00:00
compiler: add support for type parameters (aka generics)
...that was surprisingly easy.
This commit is contained in:
committed by
Ron Evans
parent
283fed16a5
commit
bb65c5ce2b
Vendored
+14
@@ -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
|
||||
}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
add: 8
|
||||
add: 8
|
||||
Reference in New Issue
Block a user