Skip to content

Commit 942994f

Browse files
committed
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 <[email protected]> Run-TryBot: Robert Findley <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
1 parent 13c407c commit 942994f

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

go/ast/astutil/rewrite.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast.
253253
a.apply(n, "X", nil, n.X)
254254
a.apply(n, "Index", nil, n.Index)
255255

256+
case *typeparams.IndexListExpr:
257+
a.apply(n, "X", nil, n.X)
258+
a.applyList(n, "Indices")
259+
256260
case *ast.SliceExpr:
257261
a.apply(n, "X", nil, n.X)
258262
a.apply(n, "Low", nil, n.Low)
@@ -439,13 +443,7 @@ func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast.
439443
}
440444

441445
default:
442-
if ix := typeparams.GetIndexExprData(n); ix != nil {
443-
a.apply(n, "X", nil, ix.X)
444-
// *ast.IndexExpr was handled above, so n must be an *ast.MultiIndexExpr.
445-
a.applyList(n, "Indices")
446-
} else {
447-
panic(fmt.Sprintf("Apply: unexpected node type %T", n))
448-
}
446+
panic(fmt.Sprintf("Apply: unexpected node type %T", n))
449447
}
450448

451449
if a.post != nil && !a.post(&a.cursor) {

internal/typeparams/typeparams_go117.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ func PackIndexExpr(x ast.Expr, lbrack token.Pos, indices []ast.Expr, rbrack toke
5353
// this Go version. Its methods panic on use.
5454
type IndexListExpr struct {
5555
ast.Expr
56+
X ast.Expr // expression
57+
Lbrack token.Pos // position of "["
58+
Indices []ast.Expr // index expressions
59+
Rbrack token.Pos // position of "]"
5660
}
5761

5862
// ForTypeSpec returns an empty field list, as type parameters on not supported

0 commit comments

Comments
 (0)