-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Go: Fix missing promoted fields due to name clash #18001
base: main
Are you sure you want to change the base?
Conversation
Hmm, the tests pass locally for me. I'll have to look into that more. |
7c51705
to
85a19e8
Compare
NCField should be promoted to EmbedsNameClash. Currently it isn't because its embedded parent pkg2.NameClash is not a promoted field in EmbedsNameClash (because of a name clash with pkg1.NameClash), but this should not make a difference.
2547c83
to
4a05c3d
Compare
I figured it out. I was using the released CLI, but #17941 changes the extractor and hence the test results, so I needed to build and use the go extractor locally. This is ready to review now. |
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.
Haven't reviewed the tests in detail, but I'm 99% convinced the elimination of getFieldCand vs hasFieldCand is sound. One difference jumps out: getFieldCand
uses hasEmbeddedField
which doesn't look through a NamedType before using .(PointerType).getBaseType()
, getFieldOfEmbedded
does. This might make a difference if X
is embedded where X is defined type X *Y
, in a positive direction. I note hasMethodCand
uses this embedded-field predicate as well.
Definitely needs DCA.
When two embedded fields at different depths have the same name (but are not the same type - they are in different packages and happen to have the same name) then we don't treat the second one correctly and we don't promote any of its fields or methods. This turns out to be because of a condition that was added to avoid non-termination on cyclic structs in github/codeql-go#184 which only checked the name of the embedded field. The fix is to also check the type.
While looking into this I noticed that we have two different predicates for calculating field candidates. This PR includes a refactoring to remove the redundancy and make the code easier to understand.