golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.68k stars 17.49k forks source link

x/tools/gopls: [type go2] add a flag to support the new bracket syntax #40316

Closed OneOfOne closed 4 years ago

OneOfOne commented 4 years ago

With the new bracket syntax probably being the default for the go2go branch (893c5ec17), it'd be nice if there was a way to toggle it in gopls.

Right now

package main

type X[type T] struct {
    x T
}

func main() {
    var x X[int]
    x.x = 10
}

Crashes with:

crash log ```sh panic: ast.Walk: unexpected node type *ast.InstantiatedType goroutine 212 [running]: go/ast.Walk(0xebe1e0, 0xc00051e1c0, 0x7f9269ed8400, 0xc000432200) /usr/src/go2/src/go/ast/walk.go:372 +0x3046 go/ast.Walk(0xebe1e0, 0xc00051e1c0, 0xec2540, 0xc0000da910) /usr/src/go2/src/go/ast/walk.go:311 +0x5b7 go/ast.Walk(0xebe1e0, 0xc00051e1c0, 0xec1dc0, 0xc000432240) /usr/src/go2/src/go/ast/walk.go:339 +0xe7b go/ast.Walk(0xebe1e0, 0xc00051e1c0, 0xec1ac0, 0xc00033a720) /usr/src/go2/src/go/ast/walk.go:191 +0x2bf7 go/ast.walkStmtList(0xebe1e0, 0xc00051e1c0, 0xc00033a760, 0x1, 0x1) /usr/src/go2/src/go/ast/walk.go:32 +0x9e go/ast.Walk(0xebe1e0, 0xc00051e1c0, 0xec1780, 0xc0002675c0) /usr/src/go2/src/go/ast/walk.go:229 +0x1905 go/ast.Walk(0xebe1e0, 0xc00051e1c0, 0xec1d00, 0xc000267620) /usr/src/go2/src/go/ast/walk.go:352 +0xcdd go/ast.walkDeclList(0xebe1e0, 0xc00051e1c0, 0xc00051e180, 0x2, 0x2) /usr/src/go2/src/go/ast/walk.go:38 +0x9e go/ast.Walk(0xebe1e0, 0xc00051e1c0, 0xec1c80, 0xc0003ba3f0) /usr/src/go2/src/go/ast/walk.go:361 +0x23c6 go/ast.Inspect(...) /usr/src/go2/src/go/ast/walk.go:393 golang.org/x/tools/internal/lsp/cache.walkASTWithParent(0xec1c80, 0xc0003ba3f0, 0xc0000daa00) /home/oneofone/code/go/src/golang.org/x/tools/internal/lsp/cache/parse.go:423 +0x9e golang.org/x/tools/internal/lsp/cache.fixAST(0xed0360, 0xc000267050, 0xec1c80, 0xc0003ba3f0, 0xc0002c1080, 0xc0002aa280, 0x4a, 0x50, 0x0) /home/oneofone/code/go/src/golang.org/x/tools/internal/lsp/cache/parse.go:369 +0x105 golang.org/x/tools/internal/lsp/cache.parseGo(0xed0360, 0xc000267050, 0xc0002bb6c0, 0xed3fa0, 0xc000414180, 0x2, 0x0) /home/oneofone/code/go/src/golang.org/x/tools/internal/lsp/cache/parse.go:285 +0x74b golang.org/x/tools/internal/lsp/cache.(*Cache).parseGoHandle.func1(0xed02a0, 0xc0002ba540, 0x0, 0x1) /home/oneofone/code/go/src/golang.org/x/tools/internal/lsp/cache/parse.go:69 +0x59 golang.org/x/tools/internal/memoize.(*Handle).run.func1(0xed02a0, 0xc0002ba540, 0xc0004759b0, 0xc0000ce1e0) /home/oneofone/code/go/src/golang.org/x/tools/internal/memoize/memoize.go:237 +0x6b created by golang.org/x/tools/internal/memoize.(*Handle).run /home/oneofone/code/go/src/golang.org/x/tools/internal/memoize/memoize.go:231 +0x11a ```

However go tool go2go -brackets translate main.go2 works fine.

stamblerre commented 4 years ago

Thanks for the report! I think the right fix would be to add a case for *ast.InstantiatedType to go/ast.Walk. @griesemer, if that sounds OK, I'll send out a CL for that.

Edit: Actually, it was such a simple fix that I mailed the CL.

gopherbot commented 4 years ago

Change https://golang.org/cl/243717 mentions this issue: [dev.go2go] go/ast: add *ast.InstantiatedType case to go/ast.walk

gopherbot commented 4 years ago

Change https://golang.org/cl/243719 mentions this issue: [dev.go2go] go/ast: add *ast.InstantiatedType case to go/ast.Walk

OneOfOne commented 4 years ago

I can confirm that fixes the issue.