keyify: support composite literals with implied types
CompositeLiteral.Type will be nil for code like the following:
things := []Thing{
{
"",
},
}
There is no reason to call TypeOf on the Type field; the type of the
whole composite literal will be the same, and is guaranteed to be
non-nil.
Closes
@@ -128,7 +128,7 @@ func main() {
printComplit(complit, lit, lprog.Fset, lprog.Fset)
return
}
- _, ok := pkg.TypeOf(complit.Type).Underlying().(*types.Struct)
+ _, ok := pkg.TypeOf(complit).Underlying().(*types.Struct)
if !ok {
log.Fatal("not a struct initialiser")
return
@@ -154,7 +154,7 @@ func keyify(
calcPos = func(i int) token.Pos { return token.Pos(2 + i) }
}
- st, _ := pkg.TypeOf(complit.Type).Underlying().(*types.Struct)
+ st, _ := pkg.TypeOf(complit).Underlying().(*types.Struct)
newComplit := &ast.CompositeLit{
Type: complit.Type,
Lbrace: 1,
