Skip to content

Commit

Permalink
fix: handle set of variadic arg list for a ... value
Browse files Browse the repository at this point in the history
  • Loading branch information
mvertes committed May 3, 2020
1 parent 7fba3fe commit 22dfc8b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
20 changes: 20 additions & 0 deletions _test/variadic6.go
@@ -0,0 +1,20 @@
package main

import "fmt"

type A struct {
}

func (a A) f(vals ...bool) {
for _, v := range vals {
fmt.Println(v)
}
}
func main() {
bools := []bool{true}
a := A{}
a.f(bools...)
}

// Output:
// true
6 changes: 5 additions & 1 deletion interp/run.go
Expand Up @@ -821,7 +821,11 @@ func call(n *node) {
d.Set(src)
}
case variadic >= 0 && i >= variadic:
vararg.Set(reflect.Append(vararg, v(f)))
if v(f).Type() == vararg.Type() {
vararg.Set(v(f))
} else {
vararg.Set(reflect.Append(vararg, v(f)))
}
default:
dest[i].Set(v(f))
}
Expand Down

0 comments on commit 22dfc8b

Please sign in to comment.