mirror of https://github.com/golang/go.git
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't declare blank aliases
|
// handle special cases
|
||||||
if decl.Name.Value == "_" {
|
switch decl.Name.Value {
|
||||||
|
case "_":
|
||||||
|
return // don't declare blank aliases
|
||||||
|
case "init":
|
||||||
|
yyerror("cannot declare init - must be non-alias function declaration")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
package p
|
package p
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt" // use at most once (to test "imported but not used" error)
|
"fmt" // use at most once (to test "imported but not used" error)
|
||||||
"go/build"
|
"go/build"
|
||||||
. "go/build"
|
. "go/build"
|
||||||
|
|
@ -74,13 +75,19 @@ func _ => math.Sin
|
||||||
func sin => math.Sin
|
func sin => math.Sin
|
||||||
func sin1 => math.Pi // ERROR "math.Pi is not a function"
|
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
|
// alias reference to a package marks package as used
|
||||||
func _ => fmt.Println
|
func _ => fmt.Println
|
||||||
|
|
||||||
// re-exported aliases
|
// re-exported aliases
|
||||||
const Pi => math.Pi
|
const Pi => math.Pi
|
||||||
|
|
||||||
type Writer => io.Writer
|
type Writer => io.Writer
|
||||||
|
|
||||||
var Def => build.Default
|
var Def => build.Default
|
||||||
|
|
||||||
func Sin => math.Sin
|
func Sin => math.Sin
|
||||||
|
|
||||||
// type aliases denote identical types
|
// type aliases denote identical types
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue