Commit 50f66fbb authored by Robert Griesemer's avatar Robert Griesemer

cmd/compile: disallow "init" as alias

Fixes #17637.

Change-Id: I5af63b8277c0a0f9fef4880992bcb925ca088687
Reviewed-on: https://go-review.googlesource.com/32106Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
parent 89632aa1
...@@ -214,8 +214,12 @@ func (p *noder) aliasDecl(decl *syntax.AliasDecl) { ...@@ -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 @@ ...@@ -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 ...@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment