reftools
reftools copied to clipboard
cmd/fillstruct: panic when using gofillstruct
I'l trying to fill out a simple struct like:
type rolleInformation struct {
XMLName xml.Name xml:"RolleInformation"
VirksomhedSimpelIdentifikatorList []virksomhedSimpelIdentifikator xml:"VirksomhedSimpelIdentifikator"
}
go version go1.10.1 linux/amd64
using gofillstruct via vim-go and the commit SHA I have is 6b560397c33c5265649b5d2b3cdf6bbbd904f5d4
Error: panic: interface conversion: ast.Expr is *ast.BasicLit, not *ast.KeyValueExpr
goroutine 1 [running]: main.zeroValue(0xc4200936d0, 0xc422707e60, 0xc4285eabc0, 0x68c5e0, 0xc4258c23c0, 0x0, 0x1, 0xc42e848f88, 0x4d8d0a, 0x0)
/home/kgn/go/src/github.com/davidrjenni/reftools/cmd/fillstruct/fill.go:42 +0x259
main.byLine.func1(0x68b9a0, 0xc4285eabc0, 0xc53011e195f9201) /home/kgn/go/src/github.com/davidrjenni/reftools/cmd/fillstruct/main.go:269 +0x3ee go/ast.inspector.Visit(0xc42ac8d380, 0x68b9a0, 0xc4285eabc0, 0x4d8d0a, 0x0) /usr/lib/go/src/go/ast/walk.go:373 +0x3a go/ast.Walk(0x68b040, 0xc42ac8d380, 0x68b9a0, 0xc4285eabc0) /usr/lib/go/src/go/ast/walk.go:52 +0x66 go/ast.walkExprList(0x68b040, 0xc42ac8d380, 0xc42a1ff5a0, 0x1, 0x1) /usr/lib/go/src/go/ast/walk.go:26 +0x81 go/ast.Walk(0x68b040, 0xc42ac8d380, 0x68b9a0, 0xc4285eac00) /usr/lib/go/src/go/ast/walk.go:104 +0x42b go/ast.walkExprList(0x68b040, 0xc42ac8d380, 0xc42a1ff5b0, 0x1, 0x1) /usr/lib/go/src/go/ast/walk.go:26 +0x81 go/ast.Walk(0x68b040, 0xc42ac8d380, 0x68b620, 0xc4285eac40) /usr/lib/go/src/go/ast/walk.go:207 +0x20fa go/ast.walkStmtList(0x68b040, 0xc42ac8d380, 0xc4285eb380, 0x3, 0x4) /usr/lib/go/src/go/ast/walk.go:32 +0x81 go/ast.Walk(0x68b040, 0xc42ac8d380, 0x68b7a0, 0xc42a1c6660) /usr/lib/go/src/go/ast/walk.go:224 +0x1b61 go/ast.Walk(0x68b040, 0xc42ac8d380, 0x68bc20, 0xc42a1c66c0) /usr/lib/go/src/go/ast/walk.go:344 +0xd6d go/ast.walkDeclList(0x68b040, 0xc42ac8d380, 0xc42adfda00, 0x11, 0x20) /usr/lib/go/src/go/ast/walk.go:38 +0x81 go/ast.Walk(0x68b040, 0xc42ac8d380, 0x68bba0, 0xc42cbf8100) /usr/lib/go/src/go/ast/walk.go:353 +0x2650 go/ast.Inspect(0x68bba0, 0xc42cbf8100, 0xc42ac8d380) /usr/lib/go/src/go/ast/walk.go:385 +0x4b main.byLine(0xc4200a6480, 0xc4200c6180, 0x40, 0x105, 0x68ace0, 0xc42007e4d0) /home/kgn/go/src/github.com/davidrjenni/reftools/cmd/fillstruct/main.go:246 +0x3c9 main.main() /home/kgn/go/src/github.com/davidrjenni/reftools/cmd/fillstruct/main.go:126 +0x339
@desdic, thanks for the bug report. I'll look into it.
Figured out that it only panics if I do it on a slice of a structure like
type t struct { test string }
tt []t
so its more a user (read me) error than a real problem :)
Thank you for following up so quickly. I think there is still a bug - fillstruct should obviously display an error message instead of panicing.
@desdic, I'm having trouble reproducing the crash. Do you mind posting the complete source file and the exact position where you executed the fillstruct command? Thank you.
@davidrjenni Sure .. but I made a smaller example to reproduce:
package main
import "fmt"
type t1 struct { T2List []t2 } type t2 struct { Tname string }
func main() {
tt := []struct {
tlist []t1
}{
{[]t1{}}, // Pointing to t1 and then running GoFillStruct causes panic
}
fmt.Println(tt)
}