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

Incorrect generation of type in a slice in a map in a struct #225

Open
posener opened this issue Aug 12, 2017 · 2 comments
Open

Incorrect generation of type in a slice in a map in a struct #225

posener opened this issue Aug 12, 2017 · 2 comments

Comments

@posener
Copy link
Contributor

posener commented Aug 12, 2017

For the following go file:

package bug

type Struct struct {
	Field map[string][]Obj
}

type Obj string

running ffjson results in a go file that can't be compiled:

handle_Field:

	/* handler: j.Field type=map[string][]bug.Obj kind=map quoted=false*/

	{

		{
			if tok != fflib.FFTok_left_bracket && tok != fflib.FFTok_null {
				return fs.WrapErr(fmt.Errorf("cannot unmarshal %s into Go value for ", tok))
			}
		}

		if tok == fflib.FFTok_null {
			j.Field = nil
		} else {

			j.Field = make(map[string][]bug.Obj, 0)

			wantVal := true

			for {

				var k string
...

Notice the bug.Obj which should be just Obj.
Thanks

@posener posener changed the title Icorrect generation of type in a slice in a map in a struct Incorrect generation of type in a slice in a map in a struct Mar 3, 2018
@brycewilson-wf
Copy link

Just wanted to chime in that I'm also running into this issue.

@drew-richardson
Copy link

Here's another example

package foo

//go:generate ffjson foo.go

type props struct {
	Series map[int][]*series `json:"series"`
}

type series struct {
	Name string `json:"name"`
}

which after running go generate ./... creates this snippet of code which does not compile

		if tok == fflib.FFTok_null {
			j.Series = nil
		} else {

			j.Series = make(map[int][]*foo.series, 0)

			wantVal := true

			for {

				var k int

				var tmpJSeries []*foo.series

				tok = fs.Scan()
				if tok == fflib.FFTok_error {
					goto tokerror
$ go build ./...
# github.com/drew-richardson/foo
foo/foo_ffjson.go:182:31: undefined: foo
foo/foo_ffjson.go:190:23: undefined: foo
arichard@gentoo:~/dist/go> 

I believe the correct code may be j.Series = make(map[int][]*series, 0) and j.Series = make(map[int][]*series, 0)

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

3 participants