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: 's avatarMatthew Dempsky <mdempsky@google.com>
parent 89632aa1
......@@ -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
......
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