Skip to content

Commit 02a56b0

Browse files
committed
47781-parameterized-go-ast.md: rename MultiIndexExpr to IndexListExpr
Following discussion in golang/go#47781, MultiIndexExpr was renamed to IndexListExpr. Change-Id: Ib8b0d138265d34b5764f5684a12c560838718ae2 Reviewed-on: https://go-review.googlesource.com/c/proposal/+/348382 Reviewed-by: Robert Griesemer <[email protected]>
1 parent 97a4398 commit 02a56b0

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

design/47781-parameterized-go-ast.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,29 @@ To represent type parameters in type and function declarations, both `ast.TypeSp
4141

4242
### For type and function instantiation
4343

44-
To represent both type and function instantiation with type arguments, we introduce a new node type `ast.MultiIndexExpr`, which is an `Expr` node similar to `ast.IndexExpr`, but with a slice of indices rather than a single index:
44+
To represent both type and function instantiation with type arguments, we introduce a new node type `ast.IndexListExpr`, which is an `Expr` node similar to `ast.IndexExpr`, but with a slice of indices rather than a single index:
4545

4646
```go
47-
type MultiIndexExpr struct {
47+
type IndexListExpr struct {
4848
X Expr
4949
Lbrack token.Pos
5050
Indices []Expr
5151
Rbrack token.Pos
5252
}
5353

54-
func (*MultiIndexExpr) End() token.Pos
55-
func (*MultiIndexExpr) Pos() token.Pos
54+
func (*IndexListExpr) End() token.Pos
55+
func (*IndexListExpr) Pos() token.Pos
5656
```
5757

58-
Type and function instance expressions will be parsed into a single `IndexExpr` if there is only one index, and a `MultiIndexExpr` if there is more than one index. Specifically, when encountering an expression `f[expr1, ..., exprN]` with `N` argument expressions, we parse as follows:
58+
Type and function instance expressions will be parsed into a single `IndexExpr` if there is only one index, and an `IndexListExpr` if there is more than one index. Specifically, when encountering an expression `f[expr1, ..., exprN]` with `N` argument expressions, we parse as follows:
5959

6060
1. If `N == 1`, as in normal index expressions `f[expr]`, we parse an `IndexExpr`.
61-
2. If `N > 1`, parse a `MultiIndexExpr` with `Indices` set to the parsed expressions `expr1, …, exprN`
61+
2. If `N > 1`, parse an `IndexListExpr` with `Indices` set to the parsed expressions `expr1, …, exprN`
6262
3. If `N == 0`, as in the invalid expression `f[]`, we parse an `IndexExpr` with `BadExpr` for its `Index` (this matches the current behavior for invalid index expressions).
6363

6464
There were several alternatives considered for representing this syntax. At least two of these alternatives were implemented. They are worth discussing:
6565
- Add a new `ListExpr` node type that holds an expression list, to serve as the `Index` field for an `IndexExpr` when `N >= 2`. This is an elegant solution, but results in inefficient storage and, more importantly, adds a new node type that exists only to alter the meaning of an existing node. This is inconsistent with the design of other nodes in `go/ast`, where additional nodes are preferred to overloading existing nodes. Compare with `RangeStmt` and `TypeSwitchStmt`, which are distinct nodes in `go/ast`. Having distinct nodes is generally easier to work with, as each node has a more uniform composition.
66-
- Overload `ast.CallExpr` to have a `Brackets bool` field, so `f[T]` would be analogous to `f(T)`, but with `Brackets` set to `true`. This is roughly equivalent to the `MultiIndexExpr` node, and allows us to avoid adding a new type. However, it overloads the meaning of `CallExpr` and adds an additional field.
66+
- Overload `ast.CallExpr` to have a `Brackets bool` field, so `f[T]` would be analogous to `f(T)`, but with `Brackets` set to `true`. This is roughly equivalent to the `IndexListExpr` node, and allows us to avoid adding a new type. However, it overloads the meaning of `CallExpr` and adds an additional field.
6767
- Add an `Tail []Expr` field to `IndexExpr` to hold additional type arguments. While this avoids a new node type, it adds an extra field to IndexExpr even when not needed.
6868

6969
### For type restrictions

0 commit comments

Comments
 (0)