Fix method_receiver for self at class body level#662
Merged
alexcrocha merged 2 commits intomainfrom Mar 13, 2026
Merged
Conversation
8187d55 to
e7f7901
Compare
e7f7901 to
b5d7bb1
Compare
st0012
approved these changes
Mar 13, 2026
| context.index_uri("file:///foo.rb", source); | ||
| assert_eq!(44, context.graph().definitions.len()); | ||
| assert_eq!(7, context.graph().constant_references.len()); | ||
| assert_eq!(9, context.graph().constant_references.len()); |
Member
There was a problem hiding this comment.
Should we create singleton class for attr_reader calls too? If not, should we stop creating one for alias_method calls? Can be a follow up PR
Contributor
Author
There was a problem hiding this comment.
That's a fair question. Let's do a follow up PR for this. I don't know the answer yet but I'll leave it for tomorrow
st0012
reviewed
Mar 13, 2026
At class body level, self is the class object. Method calls on it (self.bar, bar, Foo.bar) all resolve through the singleton class. method_receiver now sets is_singleton_name for Class, Module, and SingletonClass definitions, producing <Foo> consistently
b5d7bb1 to
3f5e7fa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #657
At class body level,
selfis the class object. Method calls on it (self.bar,bar,Foo.bar) all resolve through the singleton class.method_receiverwas not settingis_singleton_namein theSelfNode | Nonearm forClass,Module, andSingletonClassdefinitions, soself.barinsideclass Fooreturned receiverFoowhileFoo.barreturned<Foo>.Now all three produce
<Foo>consistently.Tests
self_at_class_level_matches_constantself.barinsideclass FoovsFoo.bazoutside<Foo>implicit_at_class_levelbarinsideclass Foo<Foo>self_at_module_levelself.barinsidemodule Foo<Foo>self_inside_singleton_classself.barinsideclass << self<<Foo>>implicit_inside_singleton_classbarinsideclass << self<<Foo>>at_top_levelself.barat top levelObjectCount assertions in
indexing_the_same_document_twiceupdated:alias_methodcalls at class body level now create singleton names and constant references.