cmd/gc: disallow selectors to the blank identifier

Fixes #4941.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7415051
This commit is contained in:
Daniel Morsing 2013-03-04 17:01:42 +01:00
parent cea46387b9
commit b65acaeab2
2 changed files with 9 additions and 0 deletions

View file

@ -761,6 +761,10 @@ reswitch:
n->op = ODOTPTR;
checkwidth(t);
}
if(isblank(n->right)) {
yyerror("cannot refer to blank field or method");
goto error;
}
if(!lookdot(n, t, 0)) {
if(lookdot(n, t, 1))
yyerror("%N undefined (cannot refer to unexported field or method %S)", n, n->right->sym);

View file

@ -9,8 +9,13 @@
package _ // ERROR "invalid package name _"
var t struct {
_ int
}
func main() {
_() // ERROR "cannot use _ as value"
x := _+1 // ERROR "cannot use _ as value"
_ = x
_ = t._ // ERROR "cannot refer to blank field"
}