1
0
mirror of https://github.com/golang/go synced 2024-11-26 16:57:14 -07:00

go/types, types2: avoid spurious "declared and not used" error

Fixes #60906.

Change-Id: Iba117b36041f72a54ce82cc914f8fa3b07a6fb2e
Reviewed-on: https://go-review.googlesource.com/c/go/+/504877
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
This commit is contained in:
Robert Griesemer 2023-06-21 11:14:34 -07:00 committed by Gopher Robot
parent e45202f215
commit b1f1fb2950
3 changed files with 13 additions and 0 deletions

View File

@ -184,6 +184,7 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) (isFuncInst boo
if !valid {
check.errorf(e.Pos(), NonSliceableOperand, invalidOp+"cannot index %s", x)
check.use(e.Index)
x.mode = invalid
return false
}

View File

@ -186,6 +186,7 @@ func (check *Checker) indexExpr(x *operand, e *typeparams.IndexExpr) (isFuncInst
if !valid {
// types2 uses the position of '[' for the error
check.errorf(x, NonIndexableOperand, invalidOp+"cannot index %s", x)
check.use(e.Indices...)
x.mode = invalid
return false
}

View File

@ -0,0 +1,11 @@
// Copyright 2023 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 p
func _() {
var x int
var f func() []int
_ = f /* ERROR "cannot index f" */ [x]
}