Skip to content

Commit

Permalink
Fix bug of [*] {**} [**]
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Nov 2, 2023
1 parent 2c24335 commit 33b59ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/katakata_irb/type_analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ def evaluate_hash(node, scope)
keys << evaluate(assoc.key, scope)
values << evaluate(assoc.value, scope)
when Prism::AssocSplatNode
next unless assoc.value # def f(**); {**}

hash = evaluate assoc.value, scope
unless hash.is_a?(KatakataIrb::Types::InstanceType) && hash.klass == Hash
hash = method_call hash, :to_hash, [], nil, nil, scope
Expand Down Expand Up @@ -1083,13 +1085,15 @@ def evaluate_multi_write_receiver(node, scope, evaluated_receivers)
def evaluate_list_splat_items(list, scope)
items = list.flat_map do |node|
if node.is_a? Prism::SplatNode
next unless node.expression # def f(*); [*]

splat = evaluate node.expression, scope
array_elem, non_array = partition_to_array splat.nonnillable, :to_a
[*array_elem, *non_array]
else
evaluate node, scope
end
end.uniq
end.compact.uniq
KatakataIrb::Types::UnionType[*items]
end

Expand Down
2 changes: 2 additions & 0 deletions test/test_type_analyze.rb
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ def test_def
assert_call('def f(a,...); 1.', include: Integer)
assert_call('def f(...); g(...); 1.', include: Integer)
assert_call('def f(*,**,&); g(*,**,&); 1.', include: Integer)
assert_call('def f(*,**,&); {**}.', include: Hash)
assert_call('def f(*,**,&); [*,**].', include: Array)
assert_call('class Array; def f; self.', include: Array)
end

Expand Down

0 comments on commit 33b59ca

Please sign in to comment.