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

[prototype runtime --todo] Consider accessibility mismatch #1539

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions lib/rbs/prototype/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,22 @@ def skip_mixin?(type_name:, module_name:, mixin_class:)
end
end

def skip_singleton_method?(module_name:, name:)
def skip_singleton_method?(module_name:, method:, accessibility:)
return false unless @builder.env.module_class_entry(module_name.absolute!)

@builder.build_singleton(module_name.absolute!).methods.has_key?(name)
method_definition = @builder.build_singleton(module_name.absolute!).methods[method.name]
return false unless method_definition

method_definition.accessibility == accessibility
end

def skip_instance_method?(module_name:, name:)
def skip_instance_method?(module_name:, method:, accessibility:)
return false unless @builder.env.module_class_entry(module_name.absolute!)

@builder.build_instance(module_name.absolute!).methods.has_key?(name)
method_definition = @builder.build_instance(module_name.absolute!).methods[method.name]
return false unless method_definition

method_definition.accessibility == accessibility
end

def skip_constant?(module_name:, name:)
Expand Down Expand Up @@ -303,9 +309,8 @@ def target_method?(mod, instance: nil, singleton: nil)
def generate_methods(mod, module_name, members)
module_name_absolute = to_type_name(const_name!(mod), full_name: true).absolute!
mod.singleton_methods.select {|name| target_method?(mod, singleton: name) }.sort.each do |name|
next if todo_object&.skip_singleton_method?(module_name: module_name_absolute, name: name)

method = mod.singleton_class.instance_method(name)
next if todo_object&.skip_singleton_method?(module_name: module_name_absolute, method: method, accessibility: :public)

if can_alias?(mod.singleton_class, method)
members << AST::Members::Alias.new(
Expand Down Expand Up @@ -341,9 +346,8 @@ def generate_methods(mod, module_name, members)
members << AST::Members::Public.new(location: nil)

public_instance_methods.sort.each do |name|
next if todo_object&.skip_instance_method?(module_name: module_name_absolute, name: name)

method = mod.instance_method(name)
next if todo_object&.skip_instance_method?(module_name: module_name_absolute, method: method, accessibility: :public)

if can_alias?(mod, method)
members << AST::Members::Alias.new(
Expand Down Expand Up @@ -381,11 +385,10 @@ def generate_methods(mod, module_name, members)
members << AST::Members::Private.new(location: nil)

private_instance_methods.sort.each do |name|
next if todo_object&.skip_instance_method?(module_name: module_name_absolute, name: name)

added = true
method = mod.instance_method(name)
next if todo_object&.skip_instance_method?(module_name: module_name_absolute, method: method, accessibility: :private)

added = true
if can_alias?(mod, method)
members << AST::Members::Alias.new(
new_name: method.name,
Expand Down
4 changes: 4 additions & 0 deletions test/rbs/runtime_prototype_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ def public_todo; end
private def private_todo; end
def self.singleton_defined; end
def self.singleton_todo; end
private def accessibility_mismatch; end

CONST_DEFINED = 1
CONST_TODO = 1
Expand All @@ -643,6 +644,7 @@ module MixinDefined
def public_defined: () -> void
private def private_defined: () -> void
def self.singleton_defined: () -> void
def accessibility_mismatch: () -> void
CONST_DEFINED: Integer
end
module TodoModule
Expand All @@ -668,6 +670,8 @@ def public_todo: () -> untyped

private

def accessibility_mismatch: () -> untyped

def private_todo: () -> untyped

CONST_TODO: ::Integer
Expand Down