From: Robert Griesemer Date: Fri, 19 Oct 2012 17:11:06 +0000 (-0700) Subject: go spec: define make() restrictions as for index expressions X-Git-Tag: go1.1rc2~2098 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3bde00033b8d1ff7c494d10b1343178c32abb7ad;p=gostls13.git go spec: define make() restrictions as for index expressions This is a language change: Until now, the spec required run- time panics for some of these errors. Note that gc and gccgo implemented this inconsistently, and that both compilers already reported compile-time errors in some cases. This change makes make() behave along the same vein as index expressions. This addresses the spec aspect of issue 4085. R=r, rsc, iant, ken CC=golang-dev https://golang.org/cl/6725053 --- diff --git a/doc/go_spec.html b/doc/go_spec.html index dc08db991d..45dd1e2939 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -4920,15 +4920,18 @@ make(T, n) channel asynchronous channel of type T, buffer size n

-The arguments n and m must be of integer type. -A run-time panic occurs if n -is negative or larger than m, or if n or -m cannot be represented by an int. +The size arguments n and m must be integer values. +A constant size argument must not be negative, and +if both n and m are provided and are constant, then +n must be no larger than m. +If n is negative or larger than m at run time, +a run-time panic occurs.

 s := make([]int, 10, 100)       // slice with len(s) == 10, cap(s) == 100
-s := make([]int, 10)            // slice with len(s) == cap(s) == 10
+s := make([]int, 1e3)           // slice with len(s) == cap(s) == 1000
+s := make([]int, 10, 0)	        // illegal: len(s) > cap(s)
 c := make(chan int, 10)         // channel with a buffer size of 10
 m := make(map[string]int, 100)  // map with initial space for 100 elements