Skip to content

Pick most specific parent class during linearization #3572

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

Merged

Conversation

vinistock
Copy link
Member

@vinistock vinistock commented Jun 2, 2025

Motivation

Closes #3513

Since the order of file discovery during indexing does not necessarily match the require order, we may end up discovering a re-opening of an existing class before its initial definition.

In re-openings, it's quite common to omit the parent class. Currently, we're incorrectly just finding the parent class based on the first one we can find, but that means that if the re-opening was indexed first we ignore the real parent class.

Implementation

I changed the loop that we use to find parent classes to prefer specific parent classes that aren't the implicit default (::Object). That way, if there's a more specific definition of the class, we find that one - which is the one that's actually setting the parent.

Note: if the developer makes a mistake and defines the same class with two different parents, we will linearize based on the first one found. I believe this is acceptable since Ruby will raise when you try to do this.

Automated Tests

Added a test that reproduces the behaviour.

Copy link
Member Author


How to use the Graphite Merge Queue

Add the label graphite-merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@vinistock vinistock added bugfix This PR will fix an existing bug server This pull request should be included in the server gem's release notes labels Jun 2, 2025 — with Graphite App
@vinistock vinistock self-assigned this Jun 2, 2025
@vinistock vinistock requested review from alexcrocha and Morriar June 2, 2025 16:13
@vinistock vinistock marked this pull request as ready for review June 2, 2025 16:13
@vinistock vinistock requested a review from a team as a code owner June 2, 2025 16:13
@vinistock vinistock merged commit 1f3e440 into main Jun 2, 2025
46 checks passed
@vinistock vinistock deleted the 06-02-pick_most_specific_parent_class_during_linearization branch June 2, 2025 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This PR will fix an existing bug server This pull request should be included in the server gem's release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect ancestor linearization for re-opens that omit the parent class
2 participants