-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix Embedded Pointer #358
Fix Embedded Pointer #358
Conversation
fieldType := field.Type() | ||
|
||
if ptr, ok := fieldType.(*types.Pointer); ok { | ||
fieldType = ptr.Elem() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens when the embedded pointer is null? Worth adding a test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, good question, nothing will happen here. But I would expect a runtime panic. What do you think we should do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can it return null and do the normal error bubbling dance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah ok, I'll come up with a test. Might involve slightly more messing around here since we'd need to know if it was a pointer that we matched to in template.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, after reviewing this a bit I think this is going to be a bigger change. Embeds can be pathological when they are more than a single embed deep with a mix of pointers thrown in.
I think for now we merge this and maybe log that as a separate issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fix Embedded Pointer
Fixes the first part of #356
codegen.findField
was not accounting for anonymous pointer types and was generating a redundant resolver. This change fixes this so that these pointers are unwrapped and the element type is considered recursively as a match for the field.