Skip to content

Commit

Permalink
Fix lambda with numbered parameter error
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Oct 25, 2024
1 parent c9dfd60 commit 4465c82
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/repl_type_completor/type_analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,12 @@ def evaluate_lambda_node(node, scope)

block_scope = Scope.new scope, { **local_table, Scope::BREAK_RESULT => nil, Scope::NEXT_RESULT => nil, Scope::RETURN_RESULT => nil }
block_scope.conditional do |s|
assign_parameters node.parameters.parameters, s, [], {} if node.parameters.is_a?(Prism::ParametersNode) && node.parameters.parameters
case node.parameters
when Prism::NumberedParametersNode
assign_numbered_parameters node.parameters.maximum, s, [Types::OBJECT] * node.parameters.maximum, {}
when Prism::BlockParametersNode
assign_parameters node.parameters.parameters, s, [], {} if node.parameters.parameters
end
evaluate node.body, s if node.body
end
block_scope.merge_jumps
Expand Down
9 changes: 9 additions & 0 deletions test/repl_type_completor/test_type_analyze.rb
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,15 @@ def test_call_parameter
assert_call('f((x=1)=>1); x.', include: Integer)
end

def test_lambda_args
assert_call('->(*a){a.', include: Array)
assert_call('->(**a){a.', include: Hash)
assert_call('->(a=1){a.', include: Integer)
assert_call('->a{a.', include: Object)
assert_call('->(){1.', include: Integer)
assert_call('->{_1.', include: Object)
end

def test_block_args
assert_call('[1,2,3].tap{|a| a.', include: Array)
assert_call('[1,2,3].tap{|a,| a.', include: Integer)
Expand Down

0 comments on commit 4465c82

Please sign in to comment.