As an alternative to CL 312149, add a catch-all error message in
exprInternal when encountering a ListExpr, rather than panicking.
We still might want something like CL 312149 to improve the error
message or recovery from bad indexing.
Change-Id: I865f7cc4eefa4a3b7bd8f3100df96d0144e1712f
Reviewed-on: https://go-review.googlesource.com/c/go/+/313909
Trust: Robert Findley <rfindley@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
return []ast.Expr{expr}
}
+func IsListExpr(n ast.Node) bool {
+ return false
+}
+
func Get(ast.Node) *ast.FieldList {
return nil
}
return nil
}
+func IsListExpr(n ast.Node) bool {
+ _, ok := n.(*ast.ListExpr)
+ return ok
+}
+
func Get(n ast.Node) *ast.FieldList {
switch n := n.(type) {
case *ast.TypeSpec:
// types, which are comparatively rare.
default:
- panic(fmt.Sprintf("%s: unknown expression type %T", check.fset.Position(e.Pos()), e))
+ if typeparams.IsListExpr(e) {
+ check.errorf(e, _Todo, "invalid multi-index expression")
+ } else {
+ panic(fmt.Sprintf("%s: unknown expression type %T", check.fset.Position(e.Pos()), e))
+ }
}
// everything went well
func main() {
some /* ERROR "undeclared name" */ [int, int]()
}
+
+type N[T any] struct{}
+
+var _ N /* ERROR "0 arguments but 1 type parameters" */ []
+
+type I interface {
+ type map[int]int, []int
+}
+
+func _[T I]() {
+ var m map[int]int
+ _ = m[1 /* ERROR "multi-index expression" */, 2 /* ERROR "expected type" */ ]
+
+ var a [3]int
+ _ = a[1 /* ERROR "multi-index expression" */, 2 /* ERROR "expected type" */ ]
+
+ var s []int
+ _ = s[1 /* ERROR "multi-index expression" */, 2 /* ERROR "expected type" */ ]
+
+ var t T
+ // TODO(rFindley) Fix the duplicate error below.
+ _ = t[1 /* ERROR "multi-index expression" */ /* ERROR "multi-index expression" */, 2 /* ERROR "expected type" */ ]
+}