From: Daniel Morsing Date: Mon, 4 Mar 2013 16:01:42 +0000 (+0100) Subject: cmd/gc: disallow selectors to the blank identifier X-Git-Tag: go1.1rc2~701 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b65acaeab24b1d93a765cbd0c53d1b6a0d7bb496;p=gostls13.git cmd/gc: disallow selectors to the blank identifier Fixes #4941. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/7415051 --- diff --git a/src/cmd/gc/typecheck.c b/src/cmd/gc/typecheck.c index 0889b92f81..fbab85d033 100644 --- a/src/cmd/gc/typecheck.c +++ b/src/cmd/gc/typecheck.c @@ -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); diff --git a/test/blank1.go b/test/blank1.go index c6e038a0d9..4edb2db702 100644 --- a/test/blank1.go +++ b/test/blank1.go @@ -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" }