1
0
mirror of https://github.com/golang/go synced 2024-11-17 17:04:47 -07:00

go/types: report correct number of arguments for make() built-in calls

Also: Added test cases for (separate) issue #37393.
      To be enabled when that issue is fixed.

Fixes #37349.
Updates #37393.

Change-Id: Ib78cb0614c0b396241af06a3aa5d37d8045c2f2e
Reviewed-on: https://go-review.googlesource.com/c/go/+/220584
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Robert Griesemer 2020-02-23 13:08:29 -08:00
parent ec4c9db210
commit 151ccd4bdb
2 changed files with 18 additions and 1 deletions

View File

@ -455,7 +455,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
x.typ = T
if check.Types != nil {
params := [...]Type{T, Typ[Int], Typ[Int]}
check.recordBuiltinType(call.Fun, makeSig(x.typ, params[:1+len(sizes)]...))
check.recordBuiltinType(call.Fun, makeSig(x.typ, params[:nargs]...))
}
case _New:

View File

@ -71,6 +71,23 @@ var builtinCalls = []struct {
{"make", `_ = make([]int, 10)`, `func([]int, int) []int`},
{"make", `type T []byte; _ = make(T, 10, 20)`, `func(p.T, int, int) p.T`},
// issue #37349
{"make", ` _ = make([]int, 0 )`, `func([]int, int) []int`},
{"make", `var l int; _ = make([]int, l )`, `func([]int, int) []int`},
{"make", ` _ = make([]int, 0, 0)`, `func([]int, int, int) []int`},
{"make", `var l int; _ = make([]int, l, 0)`, `func([]int, int, int) []int`},
{"make", `var c int; _ = make([]int, 0, c)`, `func([]int, int, int) []int`},
{"make", `var l, c int; _ = make([]int, l, c)`, `func([]int, int, int) []int`},
// TODO(gri) enable once the issue is fixed
// issue #37393
// {"make", ` _ = make([]int , 0 )`, `func([]int, int) []int`},
// {"make", `var l byte ; _ = make([]int8 , l )`, `func([]int8, byte) []int8`},
// {"make", ` _ = make([]int16 , 0, 0)`, `func([]int16, int, int) []int16`},
// {"make", `var l int16; _ = make([]string , l, 0)`, `func([]string, int16, int) []string`},
// {"make", `var c int32; _ = make([]float64 , 0, c)`, `func([]float64, int, int32) []float64`},
// {"make", `var l, c uint ; _ = make([]complex128, l, c)`, `func([]complex128, uint, uint) []complex128`},
{"new", `_ = new(int)`, `func(int) *int`},
{"new", `type T struct{}; _ = new(T)`, `func(p.T) *p.T`},