From 151ccd4bdb06d77e89f00b8172b70cfb2f49ca2b Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Sun, 23 Feb 2020 13:08:29 -0800 Subject: [PATCH] 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 --- src/go/types/builtins.go | 2 +- src/go/types/builtins_test.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/go/types/builtins.go b/src/go/types/builtins.go index 3756303dfb..cc50f677c7 100644 --- a/src/go/types/builtins.go +++ b/src/go/types/builtins.go @@ -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: diff --git a/src/go/types/builtins_test.go b/src/go/types/builtins_test.go index 9835a48267..ac0145ea87 100644 --- a/src/go/types/builtins_test.go +++ b/src/go/types/builtins_test.go @@ -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`},