From: Rob Findley Date: Wed, 14 Apr 2021 13:34:28 +0000 (-0400) Subject: go/ast: fix broken build with typeparams build constraint X-Git-Tag: go1.17beta1~651 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=bcbde83c200a7abb2b23666b59992265f3cf3621;p=gostls13.git 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 Trust: Robert Griesemer Run-TryBot: Robert Findley TryBot-Result: Go Bot Reviewed-by: Robert Griesemer --- diff --git a/src/go/ast/walk.go b/src/go/ast/walk.go index 9224264e29..ac1395fafd 100644 --- a/src/go/ast/walk.go +++ b/src/go/ast/walk.go @@ -112,7 +112,11 @@ func Walk(v Visitor, node Node) { case *IndexExpr: 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: Walk(v, n.X) diff --git a/src/go/ast/walk_typeparams.go b/src/go/ast/walk_typeparams.go index 77267a5b8c..b6621335b8 100644 --- a/src/go/ast/walk_typeparams.go +++ b/src/go/ast/walk_typeparams.go @@ -7,6 +7,10 @@ package ast +import ( + "fmt" +) + func walkFuncTypeParams(v Visitor, n *FuncType) { if n.TParams != nil { Walk(v, n.TParams) @@ -20,9 +24,11 @@ func walkTypeSpecParams(v Visitor, n *TypeSpec) { } func walkOtherNodes(v Visitor, n Node) { - if e, ok := n.(*ast.ListExpr); ok { + if e, ok := n.(*ListExpr); ok { if e != nil { - Walk(v, e) + for _, elem := range e.ElemList { + Walk(v, elem) + } } } else { panic(fmt.Sprintf("ast.Walk: unexpected node type %T", n))