1
0
mirror of https://github.com/golang/go synced 2024-11-05 15:46:11 -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:
Alan Donovan 2013-07-16 12:22:22 -04:00
parent 0117ba266d
commit da051f41cc
2 changed files with 9 additions and 14 deletions

View File

@ -158,12 +158,12 @@ func (info *PackageInfo) BuiltinCallSignature(e *ast.CallExpr) *types.Signature
var t0, t1 types.Type var t0, t1 types.Type
t0 = info.TypeOf(e) // infer arg[0] type from result type t0 = info.TypeOf(e) // infer arg[0] type from result type
if e.Ellipsis != 0 { if e.Ellipsis != 0 {
// append([]T, []T) []T // append(tslice, tslice...) []T
// append([]byte, string) []byte // append(byteslice, "foo"...) []byte
t1 = info.TypeOf(e.Args[1]) // no conversion t1 = info.TypeOf(e.Args[1]) // no conversion
} else { } else {
// append([]T, ...T) []T // append([]T, x, y, z) []T
t1 = t0.Underlying().(*types.Slice).Elem() t1 = t0.Underlying()
isVariadic = true isVariadic = true
} }
params = append(params, 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. // Note, arg0 may have any type, not necessarily tEface.
params = append(params, params = append(params,
types.NewVar(token.NoPos, nil, "", info.TypeOf(e.Args[0])), 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": case "close":
params = append(params, types.NewVar(token.NoPos, nil, "", info.TypeOf(e.Args[0]))) params = append(params, types.NewVar(token.NoPos, nil, "", info.TypeOf(e.Args[0])))

View File

@ -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. // f(x, y, z...): pass slice z straight through.
if e.Ellipsis != 0 { if e.Ellipsis != 0 {
for i, arg := range e.Args { for i, arg := range e.Args {
// TODO(gri): annoyingly Signature.Params doesn't v := emitConv(fn, b.expr(fn, arg), sig.Params().At(i).Type())
// reflect the slice type for a final ...T param. args = append(args, v)
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))
} }
return args return args
} }
@ -935,8 +930,8 @@ func (b *builder) emitCallArgs(fn *Function, sig *types.Signature, e *ast.CallEx
// and construction of slice. // and construction of slice.
if sig.IsVariadic() { if sig.IsVariadic() {
varargs := args[offset+np:] varargs := args[offset+np:]
vt := sig.Params().At(np).Type() st := sig.Params().At(np).Type().(*types.Slice)
st := types.NewSlice(vt) vt := st.Elem()
if len(varargs) == 0 { if len(varargs) == 0 {
args = append(args, nilLiteral(st)) args = append(args, nilLiteral(st))
} else { } else {