cmd/compile: fix check that ensures main.main is a function

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>
This commit is contained in:
Matthew Dempsky 2018-04-10 16:01:23 -07:00
parent 80bbad015d
commit 535ad8efb8
4 changed files with 26 additions and 1 deletions

View 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)

View file

@ -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

View file

@ -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
}

View file

@ -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.