-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle module_function with no arguments (#3018)
### Motivation Closes #2653 This PR handles the other missing part of `module_function`, which is when it gets invoked with no argument. After looking into the Ruby source code, it seems that `module_func` is a flag considered as part of the visibility scope. Invoking `module_function` will both: 1. Start marking new methods as singleton methods 2. Push `private` into the stack ### Implementation I created a new `VisibilityScope` object to help us encapsulate all aspects of visibility, so that we don't forget to handle `module_func` where necessary. Then I started handling the case of `module_function` with no arguments, which essentially pushes a new scope into the stack with `module_func: true` and visibility private. ### Automated Tests Added a few tests.
- Loading branch information
Showing
5 changed files
with
187 additions
and
37 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module RubyIndexer | ||
# Represents the visibility scope in a Ruby namespace. This keeps track of whether methods are in a public, private or | ||
# protected section, and whether they are module functions. | ||
class VisibilityScope | ||
extend T::Sig | ||
|
||
class << self | ||
extend T::Sig | ||
|
||
sig { returns(T.attached_class) } | ||
def module_function_scope | ||
new(module_func: true, visibility: Entry::Visibility::PRIVATE) | ||
end | ||
|
||
sig { returns(T.attached_class) } | ||
def public_scope | ||
new | ||
end | ||
end | ||
|
||
sig { returns(Entry::Visibility) } | ||
attr_reader :visibility | ||
|
||
sig { returns(T::Boolean) } | ||
attr_reader :module_func | ||
|
||
sig { params(visibility: Entry::Visibility, module_func: T::Boolean).void } | ||
def initialize(visibility: Entry::Visibility::PUBLIC, module_func: false) | ||
@visibility = visibility | ||
@module_func = module_func | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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