]> Cypherpunks repositories - gostls13.git/commitdiff
do not insert implicit "return;" in empty function body
authorRuss Cox <rsc@golang.org>
Mon, 27 Jul 2009 21:36:32 +0000 (14:36 -0700)
committerRuss Cox <rsc@golang.org>
Mon, 27 Jul 2009 21:36:32 +0000 (14:36 -0700)
R=ken
OCL=32239
CL=32239

src/cmd/gc/dcl.c
src/cmd/gc/go.y
test/fixedbugs/bug043.go
test/fixedbugs/bug080.go
test/fixedbugs/bug171.go [new file with mode: 0644]

index f9f778ce34322246375fdfba8b83166afc0b6a5c..31393cf8a1eab5f07ebb27c3ab66f457d9ae7a58 100644 (file)
@@ -636,7 +636,7 @@ funclit1(Node *ntype, NodeList *body)
        n->nname = f;
        n->type = ft;
        if(body == nil)
-               body = list1(nod(ORETURN, N, N));
+               body = list1(nod(OEMPTY, N, N));
        n->nbody = body;
        compile(n);
        funcdepth--;
index 597f13826c9f6197d0e3811bc8961a0d09ba6424..5b0f97e23fb8e9e6b5d1e4ab0edd536de7e410cd 100644 (file)
@@ -1196,7 +1196,7 @@ fnbody:
        {
                $$ = $2;
                if($$ == nil)
-                       $$ = list1(nod(ORETURN, N, N));
+                       $$ = list1(nod(OEMPTY, N, N));
                yyoptsemi(0);
        }
 
index a0c7eb1e9e1fdfd87542a8ece34c1a7dc142a450..65d720b8000e2980fe1e778f8c4799b6765a9836 100644 (file)
@@ -18,6 +18,6 @@ func g (x int) float ;  // BUG this doesn't
 func g (x int) float { return 0.0 }
 
 func h (x int) (u int, v int) ;  // BUG this doesn't
-func h (x int) (u int, v int) {}
+func h (x int) (u int, v int) { return; }
 
 func main() {}
index 319eb91c71970b81cb0ec2054be727cb902b5ce5..a5003d29b1f3a262c24ce431b711412ed515b3a9 100644 (file)
@@ -7,9 +7,11 @@
 package main   
        
 func f1() (x int, y float) {
+       return;
 }
 
 func f2   (x int, y float) {
+       return;
 }
 
 func main() {
diff --git a/test/fixedbugs/bug171.go b/test/fixedbugs/bug171.go
new file mode 100644 (file)
index 0000000..03f47e9
--- /dev/null
@@ -0,0 +1,10 @@
+// errchk $G $D/$F.go
+
+// Copyright 2009 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.
+
+package main
+
+func f() int { }       // ERROR "return"
+func g() (foo int) { } // ERROR "return"