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

Support &method(:name) call for block_pass #1276

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tk0miya
Copy link
Contributor

@tk0miya tk0miya commented Oct 9, 2024

Pass &method(:name) to the block argument on method call is usually used, and well-known idiom in Ruby. Therefore it is valuable to support the idiom on type check.

This gives a special treatment to it to support type checking.

Pass `&method(:name)` to the block argument on method call is usually
used, and well-known idiom in Ruby.  Therefore it is valuable to
support the idiom on type check.

This gives a special treatment to it to support type checking.
@tk0miya tk0miya force-pushed the type_construction/support_amp_method_for_block_pass branch from 66880ac to f285471 Compare October 9, 2024 16:24
if hint.is_a?(AST::Types::Proc) && value_node.type == :send && value_node.children[1] == :method && type.is_a?(AST::Types::Name::Instance) && type.name.to_s == '::Method'
method_name = value_node.children[2].children[0]
if method = calculate_interface(AST::Types::Self.instance, private: true)&.methods&.[](method_name)
# TODO: select appropriate method type from `method.method_types`.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm unsure how to choose the appropriate method type from method.method_types. So I use the first one.

assert_typing_error typing, size: 1 do |errors|
assert_any!(errors) do |error|
assert_instance_of Diagnostic::Ruby::BlockTypeMismatch, error
assert /^\^\(::Integer\) -> X\(\d+\)$/ =~ error.expected.to_s
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I use regexp to check the BlockTypeMismatch#expected. Is there a better way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant