[]struct{} leads to incorrectly generated code
Opened this issue · 0 comments
echlebek commented
The attached example leads to code that does not build. (Go 1.9 on my machine, but almost certainly on all release versions of Go.)
package ffjsonbug
type Foo struct {
Bar []struct{}
}
Here is the relevant section of generated code:
if j.Bar != nil {
buf.WriteString(`[`)
for i, v := range j.Bar {
if i != 0 {
buf.WriteString(`,`)
}
/* Inline struct. type=struct {} kind=struct */
buf.WriteString(`{}`)
}
buf.WriteString(`]`)
} else {
buf.WriteString(`null`)
}
The special case for struct{}
causes v
to be un-used.