Skip to content

Commit 151ccd4

Browse files
committed
go/types: report correct number of arguments for make() built-in calls
Also: Added test cases for (separate) issue golang#37393. To be enabled when that issue is fixed. Fixes golang#37349. Updates golang#37393. Change-Id: Ib78cb0614c0b396241af06a3aa5d37d8045c2f2e Reviewed-on: https://go-review.googlesource.com/c/go/+/220584 Reviewed-by: Ian Lance Taylor <iant@golang.org>
1 parent ec4c9db commit 151ccd4

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/go/types/builtins.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
455455
x.typ = T
456456
if check.Types != nil {
457457
params := [...]Type{T, Typ[Int], Typ[Int]}
458-
check.recordBuiltinType(call.Fun, makeSig(x.typ, params[:1+len(sizes)]...))
458+
check.recordBuiltinType(call.Fun, makeSig(x.typ, params[:nargs]...))
459459
}
460460

461461
case _New:

src/go/types/builtins_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,23 @@ var builtinCalls = []struct {
7171
{"make", `_ = make([]int, 10)`, `func([]int, int) []int`},
7272
{"make", `type T []byte; _ = make(T, 10, 20)`, `func(p.T, int, int) p.T`},
7373

74+
// issue #37349
75+
{"make", ` _ = make([]int, 0 )`, `func([]int, int) []int`},
76+
{"make", `var l int; _ = make([]int, l )`, `func([]int, int) []int`},
77+
{"make", ` _ = make([]int, 0, 0)`, `func([]int, int, int) []int`},
78+
{"make", `var l int; _ = make([]int, l, 0)`, `func([]int, int, int) []int`},
79+
{"make", `var c int; _ = make([]int, 0, c)`, `func([]int, int, int) []int`},
80+
{"make", `var l, c int; _ = make([]int, l, c)`, `func([]int, int, int) []int`},
81+
82+
// TODO(gri) enable once the issue is fixed
83+
// issue #37393
84+
// {"make", ` _ = make([]int , 0 )`, `func([]int, int) []int`},
85+
// {"make", `var l byte ; _ = make([]int8 , l )`, `func([]int8, byte) []int8`},
86+
// {"make", ` _ = make([]int16 , 0, 0)`, `func([]int16, int, int) []int16`},
87+
// {"make", `var l int16; _ = make([]string , l, 0)`, `func([]string, int16, int) []string`},
88+
// {"make", `var c int32; _ = make([]float64 , 0, c)`, `func([]float64, int, int32) []float64`},
89+
// {"make", `var l, c uint ; _ = make([]complex128, l, c)`, `func([]complex128, uint, uint) []complex128`},
90+
7491
{"new", `_ = new(int)`, `func(int) *int`},
7592
{"new", `type T struct{}; _ = new(T)`, `func(p.T) *p.T`},
7693

0 commit comments

Comments
 (0)