From c97778f4302bd0e39045c931941e32f178493f45 Mon Sep 17 00:00:00 2001
From: Robert Griesemer
Date: Wed, 5 Mar 2014 11:59:53 -0800
Subject: [PATCH] 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
---
doc/go_spec.html | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
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
--
2.48.1