Support def self.method_name singleton method in inline parser#2935
Open
RYOTA-KOBA wants to merge 1 commit intoruby:masterfrom
Open
Support def self.method_name singleton method in inline parser#2935RYOTA-KOBA wants to merge 1 commit intoruby:masterfrom
def self.method_name singleton method in inline parser#2935RYOTA-KOBA wants to merge 1 commit intoruby:masterfrom
Conversation
Previously, the inline parser emitted a diagnostic error for any method definition with a receiver (`def self.foo`, `def obj.foo`, etc.) and skipped processing it entirely. This meant that singleton methods defined with `def self.method_name` could not have their type annotations recognized. This change adds support for `def self.method_name` by: - Checking `Prism::SelfNode` specifically in `visit_def_node` and only rejecting non-self receivers (e.g., `def obj.foo`) - Adding a `kind` attribute (`:instance` | `:singleton`) to `DefMember` to distinguish between instance and singleton methods - Propagating `kind` through `Environment#resolve_type_names` - Routing singleton `DefMember`s to `build_singleton` in `MethodBuilder` All existing inline annotation formats (`#:`, `# @rbs`, `# @RBS param:`) work with singleton methods as well.
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.
Previously, the inline parser emitted a diagnostic error for any method definition with a receiver (
def self.foo,def obj.foo, etc.) and skipped processing it entirely. This meant that singleton methods defined withdef self.method_namecould not have their type annotations recognized.This change adds support for
def self.method_nameby:Prism::SelfNodespecifically invisit_def_nodeand only rejecting non-self receivers (e.g.,def obj.foo)kindattribute (:instance|:singleton) toDefMemberto distinguish between instance and singleton methodskindthroughEnvironment#resolve_type_namesDefMembers tobuild_singletoninMethodBuilderAll existing inline annotation formats (
#:,# @rbs,# @rbs param:) work with singleton methods as well.In addition
Could you also add the appropriate milestone to this PR? I do not have permission to set milestones from the GitHub UI. If this PR does not need one, please add the
no-milestonelabel instead.