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

Fixing Module#refine type signature #1064

Merged
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
2 changes: 1 addition & 1 deletion core/module.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,7 @@ class Module < Object
#
# Returns a module, where refined methods are defined.
#
def refine: (Class arg0) { (untyped arg0) -> untyped } -> self
def refine: (Module mod) { () -> void } -> Refinement

# <!--
# rdoc-file=object.c
Expand Down
5 changes: 5 additions & 0 deletions test/stdlib/Module_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ module Foo
BAR = 1
end

def test_refine
assert_send_type "(Module) { () -> void } -> Refinement",
Foo, :refine, String do nil end
end

def test_const_source_location
assert_send_type "(Symbol) -> [String, Integer]",
Foo, :const_source_location, :BAR
Expand Down
8 changes: 7 additions & 1 deletion test/stdlib/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ def wrapped_object
end

begin
return_value = spy.object.__send__(spy.method_name, *args, &spy_block)
if spy_block
return_value = spy.object.__send__(spy.method_name, *args) do |*a, **k, &b|
spy_block.call(*a, **k, &b)
end
else
return_value = spy.object.__send__(spy.method_name, *args, &spy_block)
end
Comment on lines +84 to +90
Copy link
Contributor Author

@piotaixr piotaixr Jul 16, 2022

Choose a reason for hiding this comment

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

This to go around the fact that the ruby source seems to require the block given to refine have to be a proper block a not a Proc.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks.

I would skip the test rather than adding this code, but we can do that when this actually causes a problem. 💪

rescue ::Exception => exn
exception = exn
end
Expand Down