internal/lib/reflect: call variadic check

This commit is contained in:
visualfc
2024-11-26 09:50:40 +08:00
parent fadd64c1e9
commit c2138037d2
5 changed files with 407 additions and 111 deletions

View File

@@ -6,12 +6,32 @@ import (
)
func main() {
callSlice()
callFunc()
callClosure()
callMethod()
callIMethod()
}
func demo(n1, n2, n3, n4, n5, n6, n7, n8, n9 int, a ...interface{}) (int, int) {
var sum int
for _, v := range a {
sum += v.(int)
}
return n1 + n2 + n3 + n4 + n5 + n6 + n7 + n8 + n9, sum
}
func callSlice() {
v := reflect.ValueOf(demo)
n := reflect.ValueOf(1)
r := v.Call([]reflect.Value{n, n, n, n, n, n, n, n, n,
reflect.ValueOf(1), reflect.ValueOf(2), reflect.ValueOf(3)})
println("call.slice", r[0].Int(), r[1].Int())
r = v.CallSlice([]reflect.Value{n, n, n, n, n, n, n, n, n,
reflect.ValueOf([]interface{}{1, 2, 3})})
println("call.slice", r[0].Int(), r[1].Int())
}
func callFunc() {
var f any = func(n int) int {
println("call.func")