diff --git a/src/cmd/gc/go.y b/src/cmd/gc/go.y index d64a3f82b43..6a99a275ca6 100644 --- a/src/cmd/gc/go.y +++ b/src/cmd/gc/go.y @@ -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 index 00000000000..4d0f090bcd7 --- /dev/null +++ b/test/fixedbugs/bug394.go @@ -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"