katakata_irb 0.1.7 → 0.1.8

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: d50fd34032f33c722cce1adc7118a354b2fdc31736f6d00d9557b9b72b361b65
4
- data.tar.gz: b874b7a2b3f65a91eebd447df6df55ae931d8050418942fd07b453611d8ff509
3
+ metadata.gz: e03e0f334a22895540f29f3bb27551bff9bfcbede5aac767559006edbc77118f
4
+ data.tar.gz: 4db442409ca2ac1d853b4e7675ff3ac10aed0d6ced431d1abdbe2eea7a1fa298
5
5
  SHA512:
6
- metadata.gz: c1d44c271e5ef109670345b8c85022553ab7618ffa30e4f979743912b30677fd8e9925d0b36c933d79f8aa0e7dc2be298e06db6f0a56cff442acb59b22ebc383
7
- data.tar.gz: e64e94002296f792a6bdd9b5637f0bf065c4366de653eb15161b3bc9c7aca1598e880344f393106c0ce0e92497cd2d13ee1f604619b70ebe986090a8fa1e74a2
6
+ metadata.gz: fb7d8eae8b68d497c6e0c5c0d9bc8d8455d5af5638fb680b3048166188a1035a2e36229a7555203de4f8d18bc3089b92f441f496d6e2a074ad61587805b6de82
7
+ data.tar.gz: 75ef2f2f26505c98e3550342493474f47f11623fd1342f0529249e6e902e95f5ebf03f5053974c6813beee3697c0d13cb5a0adec073c65ece35dce9a3e3f01ed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- katakata_irb (0.1.7)
4
+ katakata_irb (0.1.8)
5
5
  irb (>= 1.4.0)
6
6
  rbs
7
7
 
@@ -14,6 +14,7 @@ module KatakataIrb
14
14
  @binding, @self_object = binding, self_object
15
15
  @cache = { SELF => KatakataIrb::Types.type_from_object(self_object) }
16
16
  @local_variables = binding.local_variables.map(&:to_s).to_set
17
+ @global_variables = global_variables.map(&:to_s).to_set
17
18
  end
18
19
 
19
20
  def level() = 0
@@ -36,6 +37,8 @@ module KatakataIrb
36
37
  BaseScope.type_of(fallback: fallback) { @binding.local_variable_get(name) }
37
38
  when :const
38
39
  BaseScope.type_of(fallback: fallback) { @binding.eval name }
40
+ when :gvar
41
+ BaseScope.type_of(fallback: fallback) { @binding.eval name if @global_variables.include? name }
39
42
  end
40
43
  )
41
44
  end
@@ -95,15 +95,11 @@ module KatakataIrb::Types
95
95
  given << UnionType[*centers.drop(opts.size)]
96
96
  expected << rest.type
97
97
  end
98
- score += given.zip(expected).sum do |t, e|
99
- e = from_rbs_type e, receiver_type
100
- if intersect? t, e
101
- 1
102
- elsif (intersect?(STRING, e) && t.methods.include?(:to_str)) || (intersect?(INTEGER, e) && t.methods.include?(:to_int)) || (intersect?(ARRAY, e) && t.methods.include?(:to_ary))
103
- 0.5
104
- else
105
- 0
106
- end
98
+ if given.any?
99
+ score += given.zip(expected).count do |t, e|
100
+ e = from_rbs_type e, receiver_type
101
+ intersect?(t, e) || (intersect?(STRING, e) && t.methods.include?(:to_str)) || (intersect?(INTEGER, e) && t.methods.include?(:to_int)) || (intersect?(ARRAY, e) && t.methods.include?(:to_ary))
102
+ end.fdiv(given.size)
107
103
  end
108
104
  end
109
105
  [[method_type, given || [], expected || []], score]
@@ -114,15 +110,16 @@ module KatakataIrb::Types
114
110
  end
115
111
 
116
112
  def self.intersect?(a, b)
117
- atypes = ((a in UnionType) ? a.types : [a]).group_by(&:class)
118
- btypes = ((b in UnionType) ? b.types : [b]).group_by(&:class)
119
- intersect = ->(type, &block) do
120
- aa, bb = [atypes, btypes].map {|types| (types[type] || []).map(&block) }
121
- (aa & bb).any?
122
- end
113
+ atypes = a.types.group_by(&:class)
114
+ btypes = b.types.group_by(&:class)
123
115
  return true if atypes[ProcType] && btypes[ProcType]
124
- return true if intersect.call(SingletonType, &:module_or_class)
125
- intersect.call(InstanceType, &:klass)
116
+ if atypes[SingletonType] && btypes[SingletonType]
117
+ aa, bb = [atypes, btypes].map {|types| types[SingletonType].map(&:module_or_class) }
118
+ return true if (aa & bb).any?
119
+ end
120
+
121
+ aa, bb = [atypes, btypes].map {|types| (types[InstanceType] || []).map(&:klass) }
122
+ (aa.flat_map(&:ancestors) & bb).any?
126
123
  end
127
124
 
128
125
  def self.type_from_object(object)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KatakataIrb
4
- VERSION = "0.1.7"
4
+ VERSION = "0.1.8"
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.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - tompng
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-08 00:00:00.000000000 Z
11
+ date: 2023-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: irb