mirror of
https://github.com/golang/go
synced 2024-11-18 20:44:45 -07:00
go/ssa: use correct type for variadic parameter in wrapper methods
For some reason, the type of the last Param in a wrapper function for a variadic method (T) f(...U) had type [][]U instead of []U. (Possibly a workaround for a long-since fixed bug in go/types?) Added a sanity check to ensure that the common suffix of fn.Params and fn.Signature.Params match in type. Fixes golang/go#27453 Change-Id: I9506f4f67a7ff3a283e9ec0142f638aad00287a9 Reviewed-on: https://go-review.googlesource.com/134515 Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
18207bb12d
commit
677d2ff680
@ -446,6 +446,17 @@ func (s *sanity) checkFunction(fn *Function) bool {
|
|||||||
if p.Parent() != fn {
|
if p.Parent() != fn {
|
||||||
s.errorf("Param %s at index %d has wrong parent", p.Name(), i)
|
s.errorf("Param %s at index %d has wrong parent", p.Name(), i)
|
||||||
}
|
}
|
||||||
|
// Check common suffix of Signature and Params match type.
|
||||||
|
if sig := fn.Signature; sig != nil {
|
||||||
|
j := i - len(fn.Params) + sig.Params().Len() // index within sig.Params
|
||||||
|
if j < 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !types.Identical(p.Type(), sig.Params().At(j).Type()) {
|
||||||
|
s.errorf("Param %s at index %d has wrong type (%s, versus %s in Signature)", p.Name(), i, p.Type(), sig.Params().At(j).Type())
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
s.checkReferrerList(p)
|
s.checkReferrerList(p)
|
||||||
}
|
}
|
||||||
for i, fv := range fn.FreeVars {
|
for i, fv := range fn.FreeVars {
|
||||||
|
@ -141,13 +141,9 @@ func makeWrapper(prog *Program, sel *types.Selection) *Function {
|
|||||||
// start is the index of the first regular parameter to use.
|
// start is the index of the first regular parameter to use.
|
||||||
//
|
//
|
||||||
func createParams(fn *Function, start int) {
|
func createParams(fn *Function, start int) {
|
||||||
var last *Parameter
|
|
||||||
tparams := fn.Signature.Params()
|
tparams := fn.Signature.Params()
|
||||||
for i, n := start, tparams.Len(); i < n; i++ {
|
for i, n := start, tparams.Len(); i < n; i++ {
|
||||||
last = fn.addParamObj(tparams.At(i))
|
fn.addParamObj(tparams.At(i))
|
||||||
}
|
|
||||||
if fn.Signature.Variadic() {
|
|
||||||
last.typ = types.NewSlice(last.typ)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user