]> Cypherpunks repositories - gostls13.git/commitdiff
gc: make sure main.main has correct type
authorRuss Cox <rsc@golang.org>
Sun, 11 Apr 2010 21:51:35 +0000 (14:51 -0700)
committerRuss Cox <rsc@golang.org>
Sun, 11 Apr 2010 21:51:35 +0000 (14:51 -0700)
R=ken2
CC=golang-dev
https://golang.org/cl/883049

src/cmd/gc/go.y
test/fixedbugs/bug039.go

index 06696d52fcd63d3049351bdade77a60700a961c5..98f671988ffeed3d1379c29b530b8f68197d0df9 100644 (file)
@@ -1070,11 +1070,18 @@ fndcl:
                $3 = checkarglist($3, 1);
                $$ = nod(ODCLFUNC, N, N);
                $$->nname = $1;
-               if($3 == nil && $5 == nil)
-                       $$->nname = renameinit($1);
                n = nod(OTFUNC, N, N);
                n->list = $3;
                n->rlist = $5;
+               if(strcmp($1->sym->name, "init") == 0) {
+                       $$->nname = renameinit($1);
+                       if($3 != nil || $5 != nil)
+                               yyerror("func init must have no arguments and no return values");
+               }
+               if(strcmp(localpkg->name, "main") == 0 && strcmp($1->sym->name, "main") == 0) {
+                       if($3 != nil || $5 != nil)
+                               yyerror("func main must have no arguments and no return values");
+               }
                // TODO: check if nname already has an ntype
                $$->nname->ntype = n;
                funchdr($$);
index 30fbdbd3fab0b9a3e044322863f0ec62dc86e7d3..7ac02ceeb29e39e0e5381ab4c23a675d954d9a95 100644 (file)
@@ -6,6 +6,6 @@
 
 package main
 
-func main (x int) {    // GCCGO_ERROR "previous"
+func f (x int) {       // GCCGO_ERROR "previous"
        var x int;      // ERROR "redecl|redefinition"
 }