Commit graph

8 commits

Author SHA1 Message Date
Robert Griesemer abf9b112fd go/types, types2: more systematic use of Checker.use und useLHS
This CL re-introduces useLHS because we don't want to suppress
correct "declared but not used" errors for variables that only
appear on the LHS of an assignment (using Checker.use would mark
them as used).

This CL also adjusts a couple of places where types2 differed
from go/types (and suppressed valid "declared and not used"
errors). Now those errors are surfaced. Adjusted a handful of
tests accordingly.

Change-Id: Ia555139a05049887aeeec9e5221b1f41432c1a57
Reviewed-on: https://go-review.googlesource.com/c/go/+/478635
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Griesemer <gri@google.com>
2023-03-28 14:28:33 +00:00
Robert Griesemer ddb5a42b25 cmd/compile/internal/types2: avoid "declared but not used" errors for invalid code
Agressively mark all LHS variables in assignments as used if there
is any error in the (entire) assignment. This reduces the number of
spurious "declared but not used" errors in programs that are invalid
in the first place. This behavior is closer to the behavior of the
compiler's original type checker (types1) and lets us remove lines
of the form "_ = variable" just to satisfy test cases. It also makes
more important errors visible by not crowding them out.

Remove the Checker.useLHS function and use Checker.use instead:
useLHS didn't evaluate top-level variables, but we actually want
them to be evaluated in an error scenario so that they are getting
used (and thus we don't get the "declared but not used" error).

Fixes #42937.

Change-Id: Idda460f6b81c66735bf9fd597c54188949bf12b8
Reviewed-on: https://go-review.googlesource.com/c/go/+/351730
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>
2021-09-23 19:41:45 +00:00
Robert Griesemer 7a1aa7dfaf [dev.typeparams] test: adjust more test cases to match compiler -G output
With this CL, the first ~500 errorcheck tests pass when running

go run run.go -v -G

in the $GOROOT/test directory (the log output includes a few dozen
tests that are currently skipped).

Change-Id: I9eaa2319fb39a090df54f8699ddc29ffe58b1bf1
Reviewed-on: https://go-review.googlesource.com/c/go/+/274975
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>
2020-12-03 17:55:56 +00:00
griesemer b77d9fe0ea cmd/compile: better error message for assignment mismatches
Keep left-to-right order when referring to the number of
variables and values involved.

Fixes #22159.

Change-Id: Iccca12d3222f9d5e049939a9ccec07513c393faa
Reviewed-on: https://go-review.googlesource.com/68690
Reviewed-by: Russ Cox <rsc@golang.org>
2017-10-06 16:35:44 +00:00
Robert Griesemer 3c7a812485 cmd/compile: eliminate "assignment count mismatch" - not needed anymore
See https://go-review.googlesource.com/#/c/38313/ for background.
It turns out that only a few tests checked for this.

The new error message is shorter and very clear.

Change-Id: I8ab4ad59fb023c8b54806339adc23aefd7dc7b07
Reviewed-on: https://go-review.googlesource.com/38314
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-03-17 00:31:35 +00:00
Emmanuel Odeke 53fd522c0d all: make copyright headers consistent with one space after period
Follows suit with https://go-review.googlesource.com/#/c/20111.

Generated by running
$ grep -R 'Go Authors.  All' * | cut -d":" -f1 | while read F;do perl -pi -e 's/Go
Authors.  All/Go Authors. All/g' $F;done

The code in cmd/internal/unvendor wasn't changed.

Fixes #15213

Change-Id: I4f235cee0a62ec435f9e8540a1ec08ae03b1a75f
Reviewed-on: https://go-review.googlesource.com/21819
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-05-02 13:43:18 +00:00
Russ Cox 8080384a68 test: use testlib (third 100)
X ,s;^// \$G (\$D/)?\$F\.go *$;// compile;g
X ,s;^// \$G (\$D/)?\$F\.go && \$L \$F\.\$A *$;// build;g
X ,s;^// \$G (\$D/)?\$F\.go && \$L \$F\.\$A && \./\$A\.out *$;// run;g
X ,s;^// errchk \$G( -e)? (\$D/)?\$F\.go *$;// errorcheck;g

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5656083
2012-02-16 23:49:59 -05:00
Ian Lance Taylor e03a50dd11 Test case that gccgo fails (crashes rather than printing error).
R=rsc
CC=Raj_, golang-dev
https://golang.org/cl/1740044
2010-07-12 06:34:36 -07:00