fix: variadic interface conversion in call/callBin
This commit is contained in:
14
_test/variadic9.go
Normal file
14
_test/variadic9.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func Sprintf(format string, a ...interface{}) string {
|
||||||
|
return fmt.Sprintf(format, a...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println(Sprintf("Hello %s", "World!"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// Hello World!
|
||||||
@@ -801,17 +801,18 @@ func call(n *node) {
|
|||||||
values = append(values, func(f *frame) reflect.Value { return f.data[ind] })
|
values = append(values, func(f *frame) reflect.Value { return f.data[ind] })
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
var arg *itype
|
||||||
|
if variadic >= 0 && i >= variadic {
|
||||||
|
arg = n.child[0].typ.arg[variadic].val
|
||||||
|
} else {
|
||||||
|
arg = n.child[0].typ.arg[i]
|
||||||
|
}
|
||||||
if c.kind == basicLit || c.rval.IsValid() {
|
if c.kind == basicLit || c.rval.IsValid() {
|
||||||
var argType reflect.Type
|
argType := arg.TypeOf()
|
||||||
if variadic >= 0 && i >= variadic {
|
|
||||||
argType = n.child[0].typ.arg[variadic].val.TypeOf()
|
|
||||||
} else {
|
|
||||||
argType = n.child[0].typ.arg[i].TypeOf()
|
|
||||||
}
|
|
||||||
convertLiteralValue(c, argType)
|
convertLiteralValue(c, argType)
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case len(n.child[0].typ.arg) > i && n.child[0].typ.arg[i].cat == interfaceT:
|
case arg.cat == interfaceT:
|
||||||
values = append(values, genValueInterface(c))
|
values = append(values, genValueInterface(c))
|
||||||
case isRecursiveType(c.typ, c.typ.rtype):
|
case isRecursiveType(c.typ, c.typ.rtype):
|
||||||
values = append(values, genValueRecursiveInterfacePtrValue(c))
|
values = append(values, genValueRecursiveInterfacePtrValue(c))
|
||||||
@@ -1072,7 +1073,7 @@ func callBin(n *node) {
|
|||||||
values = append(values, genFunctionWrapper(c))
|
values = append(values, genFunctionWrapper(c))
|
||||||
case interfaceT:
|
case interfaceT:
|
||||||
values = append(values, genValueInterfaceValue(c))
|
values = append(values, genValueInterfaceValue(c))
|
||||||
case arrayT:
|
case arrayT, variadicT:
|
||||||
switch c.typ.val.cat {
|
switch c.typ.val.cat {
|
||||||
case interfaceT:
|
case interfaceT:
|
||||||
values = append(values, genValueInterfaceArray(c))
|
values = append(values, genValueInterfaceArray(c))
|
||||||
|
|||||||
Reference in New Issue
Block a user