1
0
mirror of https://github.com/golang/go synced 2024-11-23 00:30:07 -07:00

go/ast: fix broken build with typeparams build constraint

My rebase of https://golang.org/cl/300649 before submitting broke the
build (and tests) when using the typeparams build constraint. In a
subsequent CL I add test coverage back to cmd/dist.

This time, I've tested by running:
 - go test -tags=typeparams go/...
 - go test -tags=typeparams cmd/gofmt

All tests pass except for the new TestResolution/typeparams.go2, which I
will fix in a follow-up CL.

For #44933

Change-Id: I439d387841604cf43a90e2ce41dbe6bbbdb0306d
Reviewed-on: https://go-review.googlesource.com/c/go/+/310070
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:
Rob Findley 2021-04-14 09:34:28 -04:00 committed by Robert Findley
parent 492faaeda8
commit bcbde83c20
2 changed files with 13 additions and 3 deletions

View File

@ -112,7 +112,11 @@ func Walk(v Visitor, node Node) {
case *IndexExpr: case *IndexExpr:
Walk(v, n.X) Walk(v, n.X)
Walk(v, n.Index) // n.Index may be nil for invalid type instantiation expressions, e.g.
// var x T[].
if n.Index != nil {
Walk(v, n.Index)
}
case *SliceExpr: case *SliceExpr:
Walk(v, n.X) Walk(v, n.X)

View File

@ -7,6 +7,10 @@
package ast package ast
import (
"fmt"
)
func walkFuncTypeParams(v Visitor, n *FuncType) { func walkFuncTypeParams(v Visitor, n *FuncType) {
if n.TParams != nil { if n.TParams != nil {
Walk(v, n.TParams) Walk(v, n.TParams)
@ -20,9 +24,11 @@ func walkTypeSpecParams(v Visitor, n *TypeSpec) {
} }
func walkOtherNodes(v Visitor, n Node) { func walkOtherNodes(v Visitor, n Node) {
if e, ok := n.(*ast.ListExpr); ok { if e, ok := n.(*ListExpr); ok {
if e != nil { if e != nil {
Walk(v, e) for _, elem := range e.ElemList {
Walk(v, elem)
}
} }
} else { } else {
panic(fmt.Sprintf("ast.Walk: unexpected node type %T", n)) panic(fmt.Sprintf("ast.Walk: unexpected node type %T", n))