From d02089101c9d8375d991b679c9a1c8432e415cd8 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Fri, 22 Mar 2013 10:03:55 -0700 Subject: [PATCH] spec: add example showing missing return statement 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 | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index ebef65916e..2136d8bbe8 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -1964,6 +1964,17 @@ result parameters, the function body's statement list must end in a terminating statement.

+
+func findMarker(c <-chan int) int {
+	for i := range c {
+		if x := <-c; isMarker(x) {
+			return x
+		}
+	}
+	// invalid: missing return statement.
+}
+
+

A function declaration may omit the body. Such a declaration provides the signature for a function implemented outside Go, such as an assembly routine. -- 2.48.1