Skip to content

Commit

Permalink
Support changing of Prism::KeywordParameterNode in prism>0.16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Nov 2, 2023
1 parent 2396ae1 commit 2c24335
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/katakata_irb/type_analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -918,10 +918,12 @@ def assign_parameters(node, scope, args, kwargs)
scope[node.rest.name.to_s] = KatakataIrb::Types.array_of(*rest)
end
node.keywords.each do |n|
# n is Prism::KeywordParameterNode
# n is Prism::KeywordParameterNode (prism = 0.16.0)
# n is Prism::RequiredKeywordParameterNode | Prism::OptionalKeywordParameterNode (prism > 0.16.0)
name = n.name.to_s.delete(':')
values = [kwargs.delete(name)]
values << evaluate(n.value, scope) if n.value
# `respond_to?` is for prism > 0.16.0, `&& n.value` is for prism = 0.16.0
values << evaluate(n.value, scope) if n.respond_to?(:value) && n.value
scope[name] = KatakataIrb::Types::UnionType[*values.compact]
end
# node.keyword_rest is Prism::KeywordRestParameterNode or Prism::ForwardingParameterNode or Prism::NoKeywordsParameterNode
Expand Down
6 changes: 4 additions & 2 deletions test/test_katakata_irb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ def test_prism_node_names
ignore_class_names = [
# Not traversed
'Prism::BlockLocalVariableNode',
# Removed in prism > 0.15.1
'Prism::RequiredDestructuredParameterNode'
# Removed in prism > 0.16.0
'Prism::KeywordParameterNode',
# Added in prism > 0.16.0
'Prism::OptionalKeywordParameterNode', 'Prism::RequiredKeywordParameterNode'
]
implemented_node_class_names = [
*codes.join.scan(/evaluate_[a-z_]+/).grep(/_node$/).map { "Prism::#{_1[9..].split('_').map(&:capitalize).join}" },
Expand Down

0 comments on commit 2c24335

Please sign in to comment.