Support &method(:name) call for block_pass#1276
Merged
soutaro merged 3 commits intosoutaro:masterfrom Nov 25, 2024
Merged
Conversation
66880ac to
f285471
Compare
tk0miya
commented
Oct 9, 2024
lib/steep/type_construction.rb
Outdated
| 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`. |
Contributor
Author
There was a problem hiding this comment.
I'm unsure how to choose the appropriate method type from method.method_types. So I use the first one.
tk0miya
commented
Oct 9, 2024
| 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 |
Contributor
Author
There was a problem hiding this comment.
I use regexp to check the BlockTypeMismatch#expected. Is there a better way?
Owner
There was a problem hiding this comment.
Ah, in fact, you may want to use the newer type_check_test.rb.
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.
f285471 to
5bb36c1
Compare
tk0miya
commented
Nov 25, 2024
lib/steep/type_construction.rb
Outdated
| if method = calculate_interface(AST::Types::Self.instance, private: true)&.methods&.[](method_name) | ||
| if overload = method.method_types.find {|method_type| method_type.type.params.nil? || method_type.type.params.optional? } | ||
| type = AST::Types::Proc.new( | ||
| type: method.method_types.first&.type || raise, |
Contributor
Author
There was a problem hiding this comment.
Is it better to use overload here?
Suggested change
| type: method.method_types.first&.type || raise, | |
| type: overload, |
5bb36c1 to
cca5a96
Compare
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.
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.