Commit b65acaea authored by Daniel Morsing's avatar Daniel Morsing

cmd/gc: disallow selectors to the blank identifier

Fixes #4941.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7415051
parent cea46387
......@@ -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);
......
......@@ -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"
}
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