diff --git a/src/cmd/gc/typecheck.c b/src/cmd/gc/typecheck.c index 0889b92f818..fbab85d0331 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 c6e038a0d92..4edb2db702d 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" }