cmd/gc: silence assignment errors to undefined symbols

Fixes #6406.

R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/46900043
This commit is contained in:
Daniel Morsing 2014-01-03 21:03:20 +01:00
parent 880442f110
commit f2e94b58a0
3 changed files with 18 additions and 1 deletions

View file

@ -2680,6 +2680,11 @@ checkassign(Node *n)
n->etype = 1;
return;
}
// have already complained about n being undefined
if(n->op == ONONAME)
return;
yyerror("cannot assign to %N", n);
}

View file

@ -0,0 +1,12 @@
// errorcheck
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
func main() {
s = "bob" // ERROR "undefined.*s"
_ = s // ERROR "undefined.*s"
}

View file

@ -14,5 +14,5 @@ func mine(int b) int { // ERROR "undefined.*b"
func main() {
mine() // GCCGO_ERROR "not enough arguments"
c = mine() // ERROR "undefined.*c|not enough arguments" "cannot assign to c"
c = mine() // ERROR "undefined.*c|not enough arguments"
}