From: Robert Griesemer Date: Wed, 5 Mar 2014 19:59:53 +0000 (-0800) Subject: spec: shadowed return parameters may be disallowed X-Git-Tag: go1.3beta1~463 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=c97778f4302bd0e39045c931941e32f178493f45;p=gostls13.git spec: shadowed return parameters may be disallowed This documents the implemented behavior of both gc and gccgo as an implementation restriction. NOT A LANGUAGE CHANGE. Fixes #5425. LGTM=rsc, r, iant R=r, iant, rsc, ken CC=golang-codereviews https://golang.org/cl/71430043 --- diff --git a/doc/go_spec.html b/doc/go_spec.html index 9043431c4d..dada503574 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -5002,6 +5002,21 @@ function. A "return" statement that specifies results sets the result parameters any deferred functions are executed.

+

+Implementation restriction: A compiler may disallow an empty expression list +in a "return" statement if a different entity (constant, type, or variable) +with the same name as a result parameter is in +scope at the place of the return. +

+ +
+func f(n int) (res int, err error) {
+	if _, err := f(n-1); err != nil {
+		return  // invalid return statement: err is shadowed
+	}
+	return
+}
+

Break statements