mirror of
https://github.com/golang/go.git
synced 2024-09-21 18:38:37 +00:00
cmd/compile: disallow "init" as alias
Fixes #17637. Change-Id: I5af63b8277c0a0f9fef4880992bcb925ca088687 Reviewed-on: https://go-review.googlesource.com/32106 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
89632aa183
commit
50f66fbb66
@ -214,8 +214,12 @@ func (p *noder) aliasDecl(decl *syntax.AliasDecl) {
|
||||
return
|
||||
}
|
||||
|
||||
// don't declare blank aliases
|
||||
if decl.Name.Value == "_" {
|
||||
// handle special cases
|
||||
switch decl.Name.Value {
|
||||
case "_":
|
||||
return // don't declare blank aliases
|
||||
case "init":
|
||||
yyerror("cannot declare init - must be non-alias function declaration")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
package p
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt" // use at most once (to test "imported but not used" error)
|
||||
"go/build"
|
||||
. "go/build"
|
||||
@ -74,13 +75,19 @@ func _ => math.Sin
|
||||
func sin => math.Sin
|
||||
func sin1 => math.Pi // ERROR "math.Pi is not a function"
|
||||
|
||||
// aliases may not be called init
|
||||
func init => flag.Parse // ERROR "cannot declare init"
|
||||
|
||||
// alias reference to a package marks package as used
|
||||
func _ => fmt.Println
|
||||
|
||||
// re-exported aliases
|
||||
const Pi => math.Pi
|
||||
|
||||
type Writer => io.Writer
|
||||
|
||||
var Def => build.Default
|
||||
|
||||
func Sin => math.Sin
|
||||
|
||||
// type aliases denote identical types
|
||||
|
Loading…
Reference in New Issue
Block a user