Skip to content

Commit

Permalink
Fix _1 in each_with_index
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Oct 25, 2023
1 parent 6d236b1 commit 0859eb1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
8 changes: 1 addition & 7 deletions lib/katakata_irb/type_analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -932,13 +932,7 @@ def assign_numbered_parameters(numbered_parameters, scope, args, _kwargs)
return if numbered_parameters.empty?
max_num = numbered_parameters.map { _1[1].to_i }.max
if max_num == 1
if args.size == 0
scope['_1'] = KatakataIrb::Types::NIL
elsif args.size == 1
scope['_1'] = args.first
else
scope['_1'] = KatakataIrb::Types.array_of(*args)
end
scope['_1'] = args.first || KatakataIrb::Types::NIL
else
args = sized_splat(args.first, :to_ary, max_num) if args.size == 1
numbered_parameters.each do |name|
Expand Down
7 changes: 5 additions & 2 deletions test/test_type_analyze.rb
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,12 @@ def test_numbered_parameter
assert_call('loop{_1.', include: NilClass)
assert_call('1.tap{_1.', include: Integer)
assert_call('1.tap{_3.', include: NilClass, exclude: Integer)
assert_call('[:a].each_with_index{_1.', include: Array)
assert_call('[:a,1].tap{_1.', include: Array)
assert_call('[:a,1].tap{_2.', include: [Symbol, Integer])
assert_call('[:a,1].tap{_2; _1.', include: [Symbol, Integer])
assert_call('[:a].each_with_index{_1.', include: Symbol, exclude: Integer)
assert_call('[:a].each_with_index{_2; _1.', include: Symbol)
assert_call('[:a].each_with_index{_2.', include: Integer)
assert_call('[:a].each_with_index{_2.', include: Integer, exclude: Symbol)
end

def test_if_unless
Expand Down

0 comments on commit 0859eb1

Please sign in to comment.