]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/gc: disallow selectors to the blank identifier
authorDaniel Morsing <daniel.morsing@gmail.com>
Mon, 4 Mar 2013 16:01:42 +0000 (17:01 +0100)
committerDaniel Morsing <daniel.morsing@gmail.com>
Mon, 4 Mar 2013 16:01:42 +0000 (17:01 +0100)
Fixes #4941.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7415051

src/cmd/gc/typecheck.c
test/blank1.go

index 0889b92f8187c5c1557e691d2b2adfdf676030b7..fbab85d0331533eece4504f43fa9c462091b8510 100644 (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);
index c6e038a0d923c7553eda6a89c19077d79e744274..4edb2db702de0c77cb726f4c166d5c875fd91902 100644 (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"
 }