Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[]struct{} leads to incorrectly generated code #228

Open
echlebek opened this issue Sep 11, 2017 · 0 comments
Open

[]struct{} leads to incorrectly generated code #228

echlebek opened this issue Sep 11, 2017 · 0 comments

Comments

@echlebek
Copy link

echlebek commented Sep 11, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant