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

Push singleton context when inside singleton method #2189

Merged
merged 1 commit into from
Jun 17, 2024

Conversation

vinistock
Copy link
Member

Motivation

This PR addresses the bug identified in #2188.

When we enter a singleton method defined with def self., we need to push a singleton context to our stacks or else we will record incorrect owners for anything defined inside of it.

Implementation

Started pushing to the stacks when we enter a singleton method and popping when we are leaving.

Automated Tests

Added a test that demonstrates the issue.

@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 14, 2024
@vinistock vinistock self-assigned this Jun 14, 2024
@vinistock vinistock requested a review from a team as a code owner June 14, 2024 21:14
@vinistock vinistock requested review from andyw8 and st0012 June 14, 2024 21:14
def test_class_instance_variables_inside_self_method
index(<<~RUBY)
class Foo
def self.bar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check that the receiver is self on the def?

Consider this:

class Bar
  def Foo.bar; end
end

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do check that when entering the singleton context. I added a test to demonstrate the current behaviour (which is to associate the instance variable with the owner owner since we can't process dynamic def something.bar declarations.

@vinistock vinistock merged commit 40d964e into main Jun 17, 2024
33 checks passed
@vinistock vinistock deleted the vs/fix_class_ivar_indexing branch June 17, 2024 17:37
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.

3 participants