mirror of
https://github.com/golang/go
synced 2024-11-05 15:56:12 -07:00
go.tools/ssa: fixes required by go/types CL 11317043: the last
parameter of a variadic signature is now a slice type. R=gri CC=golang-dev https://golang.org/cl/11347043
This commit is contained in:
parent
0117ba266d
commit
da051f41cc
@ -158,12 +158,12 @@ func (info *PackageInfo) BuiltinCallSignature(e *ast.CallExpr) *types.Signature
|
||||
var t0, t1 types.Type
|
||||
t0 = info.TypeOf(e) // infer arg[0] type from result type
|
||||
if e.Ellipsis != 0 {
|
||||
// append([]T, []T) []T
|
||||
// append([]byte, string) []byte
|
||||
// append(tslice, tslice...) []T
|
||||
// append(byteslice, "foo"...) []byte
|
||||
t1 = info.TypeOf(e.Args[1]) // no conversion
|
||||
} else {
|
||||
// append([]T, ...T) []T
|
||||
t1 = t0.Underlying().(*types.Slice).Elem()
|
||||
// append([]T, x, y, z) []T
|
||||
t1 = t0.Underlying()
|
||||
isVariadic = true
|
||||
}
|
||||
params = append(params,
|
||||
@ -175,7 +175,7 @@ func (info *PackageInfo) BuiltinCallSignature(e *ast.CallExpr) *types.Signature
|
||||
// Note, arg0 may have any type, not necessarily tEface.
|
||||
params = append(params,
|
||||
types.NewVar(token.NoPos, nil, "", info.TypeOf(e.Args[0])),
|
||||
types.NewVar(token.NoPos, nil, "", tEface))
|
||||
types.NewVar(token.NoPos, nil, "", types.NewSlice(tEface)))
|
||||
|
||||
case "close":
|
||||
params = append(params, types.NewVar(token.NoPos, nil, "", info.TypeOf(e.Args[0])))
|
||||
|
@ -893,13 +893,8 @@ func (b *builder) emitCallArgs(fn *Function, sig *types.Signature, e *ast.CallEx
|
||||
// f(x, y, z...): pass slice z straight through.
|
||||
if e.Ellipsis != 0 {
|
||||
for i, arg := range e.Args {
|
||||
// TODO(gri): annoyingly Signature.Params doesn't
|
||||
// reflect the slice type for a final ...T param.
|
||||
t := sig.Params().At(i).Type()
|
||||
if sig.IsVariadic() && i == len(e.Args)-1 {
|
||||
t = types.NewSlice(t)
|
||||
}
|
||||
args = append(args, emitConv(fn, b.expr(fn, arg), t))
|
||||
v := emitConv(fn, b.expr(fn, arg), sig.Params().At(i).Type())
|
||||
args = append(args, v)
|
||||
}
|
||||
return args
|
||||
}
|
||||
@ -935,8 +930,8 @@ func (b *builder) emitCallArgs(fn *Function, sig *types.Signature, e *ast.CallEx
|
||||
// and construction of slice.
|
||||
if sig.IsVariadic() {
|
||||
varargs := args[offset+np:]
|
||||
vt := sig.Params().At(np).Type()
|
||||
st := types.NewSlice(vt)
|
||||
st := sig.Params().At(np).Type().(*types.Slice)
|
||||
vt := st.Elem()
|
||||
if len(varargs) == 0 {
|
||||
args = append(args, nilLiteral(st))
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user