fix: handle set of variadic arg list for a ... value

This commit is contained in:
Marc Vertes
2020-05-03 18:44:04 +02:00
committed by GitHub
parent 7fba3fe580
commit 22dfc8b10a
2 changed files with 25 additions and 1 deletions

20
_test/variadic6.go Normal file
View File

@@ -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

View File

@@ -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))
}