mirror of
https://github.com/golang/go
synced 2024-11-26 08:17:59 -07:00
go/types: don't panic when checking a ListExpr in exprInternal
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>
This commit is contained in:
parent
6edd573218
commit
39844971fb
@ -30,6 +30,10 @@ func UnpackExpr(expr ast.Expr) []ast.Expr {
|
|||||||
return []ast.Expr{expr}
|
return []ast.Expr{expr}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsListExpr(n ast.Node) bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func Get(ast.Node) *ast.FieldList {
|
func Get(ast.Node) *ast.FieldList {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,11 @@ func UnpackExpr(x ast.Expr) []ast.Expr {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsListExpr(n ast.Node) bool {
|
||||||
|
_, ok := n.(*ast.ListExpr)
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
func Get(n ast.Node) *ast.FieldList {
|
func Get(n ast.Node) *ast.FieldList {
|
||||||
switch n := n.(type) {
|
switch n := n.(type) {
|
||||||
case *ast.TypeSpec:
|
case *ast.TypeSpec:
|
||||||
|
@ -1805,8 +1805,12 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
|
|||||||
// types, which are comparatively rare.
|
// types, which are comparatively rare.
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
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))
|
panic(fmt.Sprintf("%s: unknown expression type %T", check.fset.Position(e.Pos()), e))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// everything went well
|
// everything went well
|
||||||
x.expr = e
|
x.expr = e
|
||||||
|
@ -7,3 +7,26 @@ package main
|
|||||||
func main() {
|
func main() {
|
||||||
some /* ERROR "undeclared name" */ [int, int]()
|
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" */ ]
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user