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:
parent
e45202f215
commit
b1f1fb2950
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
11
src/internal/types/testdata/fixedbugs/issue60906.go
vendored
Normal file
11
src/internal/types/testdata/fixedbugs/issue60906.go
vendored
Normal 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]
|
||||
}
|
Loading…
Reference in New Issue
Block a user