From: Robert Griesemer Date: Thu, 23 Sep 2021 00:28:36 +0000 (-0700) Subject: go/types: avoid "declared but not used errors" for invalid variable initializations X-Git-Tag: go1.18beta1~1219 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=c0766d2cd0453b33da74407bcb0d32bbc5392c9b;p=gostls13.git 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 Run-TryBot: Robert Griesemer TryBot-Result: Go Bot Reviewed-by: Robert Findley --- diff --git a/src/go/types/assignments.go b/src/go/types/assignments.go index c46a97f2e2..2810133a1f 100644 --- a/src/go/types/assignments.go +++ b/src/go/types/assignments.go @@ -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] }