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

Go: Fix missing promoted fields due to name clash #18001

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

owen-mc
Copy link
Contributor

@owen-mc owen-mc commented Nov 17, 2024

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.

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.
depth = min(int depthCand | exists(this.getFieldCand(name, depthCand, _))) and
result = this.getFieldCand(name, depth, _) and
strictcount(this.getFieldCand(name, depth, _)) = 1
depth = min(int depthCand | exists(Field f | this.hasFieldCand(name, f, depthCand, _))) and

Check warning

Code scanning / CodeQL

Omittable 'exists' variable Warning

This exists variable can be omitted by using a don't-care expression
in this argument
.
@owen-mc
Copy link
Contributor Author

owen-mc commented Nov 18, 2024

Hmm, the tests pass locally for me. I'll have to look into that more.

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

Successfully merging this pull request may close these issues.

1 participant