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>
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)
--- /dev/null
+// 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
--- /dev/null
+// 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
+}
--- /dev/null
+// 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.