mirror of
https://github.com/golang/go
synced 2024-11-22 10:14:40 -07:00
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:
parent
cea46387b9
commit
b65acaeab2
@ -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"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user