aboutsummaryrefslogtreecommitdiff
path: root/test/interface
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2021-09-22 21:57:19 -0700
committerRobert Griesemer <gri@golang.org>2021-09-23 19:41:45 +0000
commitddb5a42b25c63df9f11669bd4b14eeebcd2ba2bb (patch)
tree8d062a49da018d9864823dd33a463ed35c1c727b /test/interface
parentc0766d2cd0453b33da74407bcb0d32bbc5392c9b (diff)
downloadgo-ddb5a42b25c63df9f11669bd4b14eeebcd2ba2bb.tar.gz
go-ddb5a42b25c63df9f11669bd4b14eeebcd2ba2bb.zip
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>
Diffstat (limited to 'test/interface')
-rw-r--r--test/interface/pointer.go5
1 files changed, 1 insertions, 4 deletions
diff --git a/test/interface/pointer.go b/test/interface/pointer.go
index c21e4da390..a71b3f4bf8 100644
--- a/test/interface/pointer.go
+++ b/test/interface/pointer.go
@@ -24,7 +24,6 @@ type Start struct {
func (start *Start) Next() *Inst { return nil }
-
func AddInst(Inst) *Inst {
print("ok in addinst\n")
return nil
@@ -33,8 +32,6 @@ func AddInst(Inst) *Inst {
func main() {
print("call addinst\n")
var x Inst = AddInst(new(Start)) // ERROR "pointer to interface|incompatible type"
- _ = x
print("return from addinst\n")
- var y *Inst = new(Start) // ERROR "pointer to interface|incompatible type"
- _ = y
+ var y *Inst = new(Start) // ERROR "pointer to interface|incompatible type"
}