]> Cypherpunks repositories - gostls13.git/commitdiff
gc, ld: package name main no longer reserved
authorRuss Cox <rsc@golang.org>
Thu, 3 Feb 2011 19:17:20 +0000 (14:17 -0500)
committerRuss Cox <rsc@golang.org>
Thu, 3 Feb 2011 19:17:20 +0000 (14:17 -0500)
R=ken2
CC=golang-dev
https://golang.org/cl/4128054

src/cmd/gc/go.y
src/cmd/gc/lex.c
src/cmd/ld/go.c

index 994840ee831609e1889b08cd84c34bd4164cad4f..86e3cae33ccbc68c643f6762244f927dfabe3495 100644 (file)
@@ -242,14 +242,6 @@ import_package:
                
                if(safemode && !curio.importsafe)
                        yyerror("cannot import unsafe package %Z", importpkg->path);
-
-               // NOTE(rsc): This is no longer a technical restriction:
-               // the 6g tool chain would work just fine without giving
-               // special meaning to a package being named main.
-               // Other implementations might need the restriction
-               // (gccgo does), so it stays in the language and the compiler.
-               if(strcmp($2->name, "main") == 0)
-                       yyerror("cannot import package main");
        }
 
 import_safety:
index 2148d7523b3e55e83fbd4bd8b638c585fd63d902..e79d3b0f8f97fc33ee4e20dbae17d0c4a9afd826 100644 (file)
@@ -423,6 +423,15 @@ importfile(Val *f, int line)
                errorexit();
        }
 
+       // The package name main is no longer reserved,
+       // but we reserve the import path "main" to identify
+       // the main package, just as we reserve the import 
+       // path "math" to identify the standard math package.
+       if(strcmp(f->u.sval->s, "main") == 0) {
+               yyerror("cannot import \"main\"");
+               errorexit();
+       }
+
        if(strcmp(f->u.sval->s, "unsafe") == 0) {
                if(safemode) {
                        yyerror("cannot import package unsafe");
index 8966b2a1fc4587b3f9f60848e3a09a56a51a40f7..2c6a6d084b641a93ba5d32052db270702b9dc262 100644 (file)
@@ -148,8 +148,6 @@ ldpkg(Biobuf *f, char *pkg, int64 len, char *filename, int whence)
                }
                if(strcmp(pkg, "main") == 0 && strcmp(name, "main") != 0)
                        fprint(2, "%s: %s: not package main (package %s)\n", argv0, filename, name);
-               else if(strcmp(pkg, "main") != 0 && strcmp(name, "main") == 0)
-                       fprint(2, "%s: %s: importing %s, found package main", argv0, filename, pkg);
                loadpkgdata(filename, pkg, p0, p1 - p0);
        }