mirror of
https://github.com/golang/go
synced 2024-10-14 20:05:36 +00:00
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:
parent
80bbad015d
commit
535ad8efb8
|
@ -85,7 +85,7 @@ func declare(n *Node, ctxt Class) {
|
||||||
if s.Name == "init" {
|
if s.Name == "init" {
|
||||||
yyerrorl(n.Pos, "cannot declare init - must be func")
|
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")
|
yyerrorl(n.Pos, "cannot declare main - must be func")
|
||||||
}
|
}
|
||||||
externdcl = append(externdcl, n)
|
externdcl = append(externdcl, n)
|
||||||
|
|
9
test/fixedbugs/issue24801.dir/a.go
Normal file
9
test/fixedbugs/issue24801.dir/a.go
Normal 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
|
11
test/fixedbugs/issue24801.dir/main.go
Normal file
11
test/fixedbugs/issue24801.dir/main.go
Normal 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
|
||||||
|
}
|
5
test/fixedbugs/issue24801.go
Normal file
5
test/fixedbugs/issue24801.go
Normal 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.
|
Loading…
Reference in a new issue