]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: report correct number of arguments for make() built-in calls
authorRobert Griesemer <gri@golang.org>
Sun, 23 Feb 2020 21:08:29 +0000 (13:08 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 24 Feb 2020 02:36:05 +0000 (02:36 +0000)
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>
src/go/types/builtins.go
src/go/types/builtins_test.go

index 3756303dfbca9327c3b254e398e5777da0fa1d83..cc50f677c7b117ce759330b7a9be478e12b61dbf 100644 (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:
index 9835a48267061054d0697ce2855cfe312e6b776a..ac0145ea875a62223892f856ebe96582cd15084b 100644 (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`},