]> Cypherpunks repositories - gostls13.git/commitdiff
spec: add example showing missing return statement
authorRob Pike <r@golang.org>
Fri, 22 Mar 2013 17:03:55 +0000 (10:03 -0700)
committerRob Pike <r@golang.org>
Fri, 22 Mar 2013 17:03:55 +0000 (10:03 -0700)
Will help people find the rules by searching the spec by
having a comment saying "missing return";
"terminating statement" does not evoke the rule to the
uninitiated.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7838044

doc/go_spec.html

index ebef65916e045d78aa5298f67f04ea8aedb454d5..2136d8bbe8c867d8abc43cf024e60734f2665bcc 100644 (file)
@@ -1,6 +1,6 @@
 <!--{
        "Title": "The Go Programming Language Specification",
-       "Subtitle": "Version of March 20, 2013",
+       "Subtitle": "Version of March 22, 2013",
        "Path": "/ref/spec"
 }-->
 
@@ -1964,6 +1964,17 @@ result parameters, the function body's statement list must end in
 a <a href="#Terminating_statements">terminating statement</a>.
 </p>
 
+<pre>
+func findMarker(c <-chan int) int {
+       for i := range c {
+               if x := <-c; isMarker(x) {
+                       return x
+               }
+       }
+       // invalid: missing return statement.
+}
+</pre>
+
 <p>
 A function declaration may omit the body. Such a declaration provides the
 signature for a function implemented outside Go, such as an assembly routine.