diff --git a/lib/katakata_irb/type_analyzer.rb b/lib/katakata_irb/type_analyzer.rb index 370e4e4..ed6c288 100644 --- a/lib/katakata_irb/type_analyzer.rb +++ b/lib/katakata_irb/type_analyzer.rb @@ -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 diff --git a/test/test_katakata_irb.rb b/test/test_katakata_irb.rb index 52f889d..659d7db 100644 --- a/test/test_katakata_irb.rb +++ b/test/test_katakata_irb.rb @@ -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}" },