ardielle / ardielle-tools

Apache License 2.0
18 stars 19 forks source link

Embedding a Go type generated by RDL into another Go type that is hand-written causes panics in JSON serialization #80

Closed gotwarlost closed 7 years ago

gotwarlost commented 7 years ago

Test case: https://gist.github.com/gotwarlost/6cf38fc5f554ff1ec06aa4b045912060

produces:

$ rdl-bug
2017/05/12 16:13:19 {
    "id": "me",
    "name": "Krishnan",
    "Title": "Mr."
}
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
    panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x129f754]

...
boynton commented 7 years ago

Embedding a type works if you specify the embedded type, not a pointer to it. As a pointer, it is up to the containing instance to initialize it with storage before unmarshaling.