]> Cypherpunks repositories - gostls13.git/commitdiff
gc: don't fault on return outside function
authorScott Lawrence <bytbox@gmail.com>
Mon, 16 Jan 2012 23:12:25 +0000 (18:12 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 16 Jan 2012 23:12:25 +0000 (18:12 -0500)
Fixes #2598.

R=golang-dev, ality, minux.ma, mpimenov, rsc
CC=golang-dev
https://golang.org/cl/5510043

src/cmd/gc/go.y
test/fixedbugs/bug394.go [new file with mode: 0644]

index d64a3f82b43d97557afae8afa70dfb28508ec306..6a99a275ca6efe19a2794fa6454836c38d7a14e1 100644 (file)
@@ -1618,7 +1618,7 @@ non_dcl_stmt:
        {
                $$ = nod(ORETURN, N, N);
                $$->list = $2;
-               if($$->list == nil) {
+               if($$->list == nil && curfn != N) {
                        NodeList *l;
                        
                        for(l=curfn->dcl; l; l=l->next) {
diff --git a/test/fixedbugs/bug394.go b/test/fixedbugs/bug394.go
new file mode 100644 (file)
index 0000000..4d0f090
--- /dev/null
@@ -0,0 +1,10 @@
+// errchk $G $D/$F.go
+
+// Copyright 2011 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Issue 2598
+package foo
+
+return nil // ERROR "non-declaration statement outside function body"