mirror of
https://github.com/golang/go
synced 2024-11-02 09:03:03 +00:00
go/types: avoid "declared but not used errors" for invalid variable initializations
This is a partial port of CL 351669 from types2 to go/types; it only copies the fix for variable usage. Eventually we may want to use the compiler error messages for assignment errors everywhere, but that doesn't need to happen now. Change-Id: I62b024b1b29cc27c29d919de3de44f944f6e2b4d Reviewed-on: https://go-review.googlesource.com/c/go/+/351670 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
0626ac064d
commit
c0766d2cd0
1 changed files with 1 additions and 0 deletions
|
@ -237,6 +237,7 @@ func (check *Checker) initVars(lhs []*Var, origRHS []ast.Expr, returnPos token.P
|
|||
if len(lhs) != len(rhs) {
|
||||
// invalidate lhs
|
||||
for _, obj := range lhs {
|
||||
obj.used = true // avoid declared but not used errors
|
||||
if obj.typ == nil {
|
||||
obj.typ = Typ[Invalid]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue