]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: make missing package error fatal
authorRick Arnold <rickarnoldjr@gmail.com>
Fri, 9 Aug 2013 06:05:40 +0000 (16:05 +1000)
committerRob Pike <r@golang.org>
Fri, 9 Aug 2013 06:05:40 +0000 (16:05 +1000)
No longer continue assuming package main.

Fixes #4776.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/12677043

src/cmd/gc/go.y
src/cmd/gc/y.tab.c
test/fixedbugs/issue4776.go [new file with mode: 0644]

index 4fcb8c0f05b99bba61d0a4b2db07d246283879e4..7346b06b2a8a533624e741f488ed2e3736458a1f 100644 (file)
@@ -136,8 +136,7 @@ package:
        {
                prevlineno = lineno;
                yyerror("package statement must be first");
-               flusherrors();
-               mkpackage("main");
+               errorexit();
        }
 |      LPACKAGE sym ';'
        {
index 39c0b12b6421d620cf8bb05a123772d5b25cd54b..eb11ef104c7fbfad6b303f35ebd7966d177dea86 100644 (file)
@@ -2428,8 +2428,7 @@ yyreduce:
     {
                prevlineno = lineno;
                yyerror("package statement must be first");
-               flusherrors();
-               mkpackage("main");
+               errorexit();
        }
     break;
 
diff --git a/test/fixedbugs/issue4776.go b/test/fixedbugs/issue4776.go
new file mode 100644 (file)
index 0000000..c38dc09
--- /dev/null
@@ -0,0 +1,10 @@
+// errorcheck
+
+// Copyright 2013 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 4776: missing package declaration error should be fatal.
+
+type MyInt int32 // ERROR "package statement must be first"
+