From 3bde00033b8d1ff7c494d10b1343178c32abb7ad Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Fri, 19 Oct 2012 10:11:06 -0700 Subject: [PATCH] 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 --- doc/go_spec.html | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index dc08db991da..45dd1e29395 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