katakata_irb 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad93f43d988f169816f4e842bdb70eda5a866574664f6afb5c015ae60b2f2d3b
4
- data.tar.gz: 700e29af39db9a73fb71f0f2e76cf4d87bcf801e31fddaef3514416e6d3699e1
3
+ metadata.gz: aceac4c5bece32a19a242c927326fa87814f34524368a90d1742ce9f66a055d4
4
+ data.tar.gz: 0c66cdde7506e1bace2fe342dae2104434ab0622cff5578c099e6e0f9179845c
5
5
  SHA512:
6
- metadata.gz: d53414d13852cd4d88a92b841fcd20d85a19efd7cb2dd15faac245e0cd944f10e12e5176ca6b03aa82ca3bd66981c56a0a6ad228a73f9e149b1a4ee9077c4f39
7
- data.tar.gz: 734aa26486a262b1feaf059290d7526fb061a71cd584c8ec4fa4fdbeb3f8a2b1d29b9e5dd64549e33d87e9987e736aeb1be0ae366033af9533914ca38981c4a8
6
+ metadata.gz: c806348785e27e8cd604ba978c18762826f087ed1406d0fc608d8334becb7b1b6d45f7e7a275cfef94455169719ab4e6ccfb0f4aa648c518a7f34915ed81961c
7
+ data.tar.gz: 26324135a3b7b153f093da98e0b3d7824aa6969b6135b26eb85da0eecdb4a3f04b8026946f898d2b1852315102d3101104f2fadc8bb0dbdd840b7856d10cd7fc
@@ -172,6 +172,8 @@ class KatakataIrb::TypeAnalyzer
172
172
  keys << evaluate(assoc.key, scope)
173
173
  values << evaluate(assoc.value, scope)
174
174
  when Prism::AssocSplatNode
175
+ next unless assoc.value # def f(**); {**}
176
+
175
177
  hash = evaluate assoc.value, scope
176
178
  unless hash.is_a?(KatakataIrb::Types::InstanceType) && hash.klass == Hash
177
179
  hash = method_call hash, :to_hash, [], nil, nil, scope
@@ -461,7 +463,6 @@ class KatakataIrb::TypeAnalyzer
461
463
  elsif node.value
462
464
  evaluate node.value, scope
463
465
  else
464
- # For syntax invalid code like `(*a).b`
465
466
  KatakataIrb::Types::NIL
466
467
  end
467
468
  )
@@ -854,7 +855,7 @@ class KatakataIrb::TypeAnalyzer
854
855
  end
855
856
  when :splat_node
856
857
  splat_value = value ? KatakataIrb::Types.array_of(value) : KatakataIrb::Types::ARRAY
857
- assign_required_parameter node.expression, splat_value, scope
858
+ assign_required_parameter node.expression, splat_value, scope if node.expression
858
859
  end
859
860
  end
860
861
 
@@ -918,10 +919,12 @@ class KatakataIrb::TypeAnalyzer
918
919
  scope[node.rest.name.to_s] = KatakataIrb::Types.array_of(*rest)
919
920
  end
920
921
  node.keywords.each do |n|
921
- # n is Prism::KeywordParameterNode
922
+ # n is Prism::KeywordParameterNode (prism = 0.16.0)
923
+ # n is Prism::RequiredKeywordParameterNode | Prism::OptionalKeywordParameterNode (prism > 0.16.0)
922
924
  name = n.name.to_s.delete(':')
923
925
  values = [kwargs.delete(name)]
924
- values << evaluate(n.value, scope) if n.value
926
+ # `respond_to?` is for prism > 0.16.0, `&& n.value` is for prism = 0.16.0
927
+ values << evaluate(n.value, scope) if n.respond_to?(:value) && n.value
925
928
  scope[name] = KatakataIrb::Types::UnionType[*values.compact]
926
929
  end
927
930
  # node.keyword_rest is Prism::KeywordRestParameterNode or Prism::ForwardingParameterNode or Prism::NoKeywordsParameterNode
@@ -1030,7 +1033,7 @@ class KatakataIrb::TypeAnalyzer
1030
1033
  when Prism::CallNode
1031
1034
  evaluated_receivers&.[](node.receiver) || evaluate(node.receiver, scope) if node.receiver
1032
1035
  when Prism::SplatNode
1033
- evaluate_write node.expression, KatakataIrb::Types.array_of(value), scope, evaluated_receivers
1036
+ evaluate_write node.expression, KatakataIrb::Types.array_of(value), scope, evaluated_receivers if node.expression
1034
1037
  when Prism::LocalVariableTargetNode, Prism::GlobalVariableTargetNode, Prism::InstanceVariableTargetNode, Prism::ClassVariableTargetNode, Prism::ConstantTargetNode
1035
1038
  scope[node.name.to_s] = value
1036
1039
  when Prism::ConstantPathTargetNode
@@ -1081,13 +1084,15 @@ class KatakataIrb::TypeAnalyzer
1081
1084
  def evaluate_list_splat_items(list, scope)
1082
1085
  items = list.flat_map do |node|
1083
1086
  if node.is_a? Prism::SplatNode
1087
+ next unless node.expression # def f(*); [*]
1088
+
1084
1089
  splat = evaluate node.expression, scope
1085
1090
  array_elem, non_array = partition_to_array splat.nonnillable, :to_a
1086
1091
  [*array_elem, *non_array]
1087
1092
  else
1088
1093
  evaluate node, scope
1089
1094
  end
1090
- end.uniq
1095
+ end.compact.uniq
1091
1096
  KatakataIrb::Types::UnionType[*items]
1092
1097
  end
1093
1098
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KatakataIrb
4
- VERSION = "0.2.2"
4
+ VERSION = "0.2.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: katakata_irb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - tompng
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-30 00:00:00.000000000 Z
11
+ date: 2023-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: irb