When generating a new type, the parameter type was not correctly duplicated in the new AST. This is fixed by making copyNode recursive if needed. The out of order processing of generic types has also been fixed. Fixes #1488
24 lines
292 B
Go
24 lines
292 B
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
type vector interface {
|
|
[]int | [3]int
|
|
}
|
|
|
|
func sum[V vector](v V) (out int) {
|
|
for i := 0; i < len(v); i++ {
|
|
out += v[i]
|
|
}
|
|
return
|
|
}
|
|
|
|
func main() {
|
|
va := [3]int{1, 2, 3}
|
|
vs := []int{1, 2, 3}
|
|
fmt.Println(sum[[3]int](va), sum[[]int](vs))
|
|
}
|
|
|
|
// Output:
|
|
// 6 6
|