1
0
mirror of https://github.com/golang/go synced 2024-11-25 02:57:57 -07:00

do not insert implicit "return;" in empty function body

R=ken
OCL=32239
CL=32239
This commit is contained in:
Russ Cox 2009-07-27 14:36:32 -07:00
parent b388d84013
commit 0b2683d1ee
5 changed files with 15 additions and 3 deletions

View 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--;

View File

@ -1196,7 +1196,7 @@ fnbody:
{
$$ = $2;
if($$ == nil)
$$ = list1(nod(ORETURN, N, N));
$$ = list1(nod(OEMPTY, N, N));
yyoptsemi(0);
}

View 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() {}

View File

@ -7,9 +7,11 @@
package main
func f1() (x int, y float) {
return;
}
func f2 (x int, y float) {
return;
}
func main() {

10
test/fixedbugs/bug171.go Normal file
View File

@ -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"