From 942994fc75ba3b8f8cbe2f1898518dcaa2aea50d Mon Sep 17 00:00:00 2001 From: Robert Findley Date: Wed, 29 Sep 2021 11:36:49 -0400 Subject: [PATCH] internal/typeparams: use alias rather than indirection for IndexListExpr Using aliases make it easier to translate code using the new APIs. Change-Id: I9887569a3ba1d5b1434ac6cc185485433aca7090 Reviewed-on: https://go-review.googlesource.com/c/tools/+/352898 Trust: Robert Findley Run-TryBot: Robert Findley gopls-CI: kokoro TryBot-Result: Go Bot Reviewed-by: Robert Griesemer --- go/ast/astutil/rewrite.go | 12 +++++------- internal/typeparams/typeparams_go117.go | 4 ++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/go/ast/astutil/rewrite.go b/go/ast/astutil/rewrite.go index 5fe75b14c7..6d9ca23e2b 100644 --- a/go/ast/astutil/rewrite.go +++ b/go/ast/astutil/rewrite.go @@ -253,6 +253,10 @@ func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast. a.apply(n, "X", nil, n.X) a.apply(n, "Index", nil, n.Index) + case *typeparams.IndexListExpr: + a.apply(n, "X", nil, n.X) + a.applyList(n, "Indices") + case *ast.SliceExpr: a.apply(n, "X", nil, n.X) a.apply(n, "Low", nil, n.Low) @@ -439,13 +443,7 @@ func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast. } default: - if ix := typeparams.GetIndexExprData(n); ix != nil { - a.apply(n, "X", nil, ix.X) - // *ast.IndexExpr was handled above, so n must be an *ast.MultiIndexExpr. - a.applyList(n, "Indices") - } else { - panic(fmt.Sprintf("Apply: unexpected node type %T", n)) - } + panic(fmt.Sprintf("Apply: unexpected node type %T", n)) } if a.post != nil && !a.post(&a.cursor) { diff --git a/internal/typeparams/typeparams_go117.go b/internal/typeparams/typeparams_go117.go index a86d0ea406..d22899d29e 100644 --- a/internal/typeparams/typeparams_go117.go +++ b/internal/typeparams/typeparams_go117.go @@ -53,6 +53,10 @@ func PackIndexExpr(x ast.Expr, lbrack token.Pos, indices []ast.Expr, rbrack toke // this Go version. Its methods panic on use. type IndexListExpr struct { ast.Expr + X ast.Expr // expression + Lbrack token.Pos // position of "[" + Indices []ast.Expr // index expressions + Rbrack token.Pos // position of "]" } // ForTypeSpec returns an empty field list, as type parameters on not supported