Commit c97778f4 authored by Robert Griesemer's avatar Robert Griesemer

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
parent c8871933
<!--{
"Title": "The Go Programming Language Specification",
"Subtitle": "Version of March 4, 2014",
"Subtitle": "Version of March 5, 2014",
"Path": "/ref/spec"
}-->
......@@ -5002,6 +5002,21 @@ function. A "return" statement that specifies results sets the result parameters
any deferred functions are executed.
</p>
<p>
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
<a href="#Declarations_and_scope">scope</a> at the place of the return.
</p>
<pre>
func f(n int) (res int, err error) {
if _, err := f(n-1); err != nil {
return // invalid return statement: err is shadowed
}
return
}
</pre>
<h3 id="Break_statements">Break statements</h3>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment