]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix check that ensures main.main is a function
authorMatthew Dempsky <mdempsky@google.com>
Tue, 10 Apr 2018 23:01:23 +0000 (16:01 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 10 Apr 2018 23:34:12 +0000 (23:34 +0000)
The check was previously disallowing package main from even importing
a non-function symbol named "main".

Fixes #24801.

Change-Id: I849b9713890429f0a16860ef16b5dc7e970d04a4
Reviewed-on: https://go-review.googlesource.com/106120
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/gc/dcl.go
test/fixedbugs/issue24801.dir/a.go [new file with mode: 0644]
test/fixedbugs/issue24801.dir/main.go [new file with mode: 0644]
test/fixedbugs/issue24801.go [new file with mode: 0644]

index e2e21faf80264e9130a7c376ee3addb2f20cc877..ab6dd8bc390c0c96984594ebc5e63a8320b37764 100644 (file)
@@ -85,7 +85,7 @@ func declare(n *Node, ctxt Class) {
                if s.Name == "init" {
                        yyerrorl(n.Pos, "cannot declare init - must be func")
                }
-               if s.Name == "main" && localpkg.Name == "main" {
+               if s.Name == "main" && s.Pkg.Name == "main" {
                        yyerrorl(n.Pos, "cannot declare main - must be func")
                }
                externdcl = append(externdcl, n)
diff --git a/test/fixedbugs/issue24801.dir/a.go b/test/fixedbugs/issue24801.dir/a.go
new file mode 100644 (file)
index 0000000..58e6240
--- /dev/null
@@ -0,0 +1,9 @@
+// Copyright 2018 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 a
+
+type main int
+
+var X main
diff --git a/test/fixedbugs/issue24801.dir/main.go b/test/fixedbugs/issue24801.dir/main.go
new file mode 100644 (file)
index 0000000..5c7db7b
--- /dev/null
@@ -0,0 +1,11 @@
+// Copyright 2018 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
+
+import "./a"
+
+func main() {
+       a.X = 1
+}
diff --git a/test/fixedbugs/issue24801.go b/test/fixedbugs/issue24801.go
new file mode 100644 (file)
index 0000000..9b05db8
--- /dev/null
@@ -0,0 +1,5 @@
+// compiledir
+
+// Copyright 2018 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.