Skip to content

Commit

Permalink
internal/lib/reflect: call variadic check
Browse files Browse the repository at this point in the history
  • Loading branch information
visualfc committed Nov 26, 2024
1 parent b63905d commit 6c68d9a
Show file tree
Hide file tree
Showing 5 changed files with 407 additions and 111 deletions.
20 changes: 20 additions & 0 deletions cl/_testgo/reflect/in.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading

0 comments on commit 6c68d9a

Please sign in to comment.