typeprof 0.5.3 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/typeprof/analyzer.rb +25 -28
- data/lib/typeprof/container-type.rb +17 -8
- data/lib/typeprof/type.rb +5 -1
- data/lib/typeprof/version.rb +1 -1
- data/smoke/array11.rb +1 -1
- data/smoke/array6.rb +2 -2
- data/smoke/array8.rb +1 -1
- data/smoke/block-args2.rb +3 -3
- data/smoke/block-args3.rb +4 -4
- data/smoke/block-blockarg.rb +1 -1
- data/smoke/block5.rb +1 -1
- data/smoke/constant2.rb +1 -2
- data/smoke/demo5.rb +1 -1
- data/smoke/demo9.rb +1 -1
- data/smoke/hash1.rb +2 -1
- data/smoke/hash4.rb +1 -1
- data/smoke/inheritance2.rb +2 -2
- data/smoke/ivar2.rb +1 -1
- data/smoke/kernel-class.rb +1 -1
- data/smoke/kwsplat1.rb +1 -1
- data/smoke/multiple-superclass.rb +1 -1
- data/smoke/parameterizedd-self.rb +2 -2
- data/smoke/struct.rb +2 -2
- data/smoke/union-recv.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d60066fe3965ec65f9885e311f856277d0e41330478489c026fdf6b387ba2ba
|
4
|
+
data.tar.gz: 963b66fe97d98207d72645011bcd012368937ded76278d92a4b677b961c92cdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a40e89e05c1680480eb66798863ab99a4b38b3faaacdc471a6cdd45dfc1f897efcc8f613800ef28e5bc722c3504dec510ca943435873b6cb765a27f1bb073425
|
7
|
+
data.tar.gz: 94dddf2c3e465ee19093ce571d50440293118b07ab7c90203aa5ccb40c4f9eb9afe1059eff045c965006affa8f0d66d141be2064feddf9a2b1f8384f8cadae64
|
data/Gemfile.lock
CHANGED
data/lib/typeprof/analyzer.rb
CHANGED
@@ -252,6 +252,8 @@ module TypeProf
|
|
252
252
|
@rbs_reader = RBSReader.new
|
253
253
|
|
254
254
|
@terminated = false
|
255
|
+
|
256
|
+
@anonymous_struct_gen_id = 0
|
255
257
|
end
|
256
258
|
|
257
259
|
attr_reader :return_envs, :loaded_features, :rbs_reader
|
@@ -397,8 +399,9 @@ module TypeProf
|
|
397
399
|
|
398
400
|
idx = @class_defs.size
|
399
401
|
superclass = Type::Builtin[:struct]
|
400
|
-
|
401
|
-
|
402
|
+
name = "AnonymousStruct_generated_#{ @anonymous_struct_gen_id += 1 }"
|
403
|
+
@class_defs[idx] = ClassDef.new(:class, [name], superclass.idx, ep.ctx.iseq.absolute_path)
|
404
|
+
klass = Type::Class.new(:class, idx, [], superclass, name)
|
402
405
|
@class_defs[idx].klass_obj = klass
|
403
406
|
|
404
407
|
@struct_defs[ep] = klass
|
@@ -1132,35 +1135,29 @@ module TypeProf
|
|
1132
1135
|
else
|
1133
1136
|
if existing_klass != Type.any
|
1134
1137
|
error(ep, "the class \"#{ id }\" is #{ existing_klass.screen_name(self) }")
|
1135
|
-
id = :"#{ id }(dummy)"
|
1136
1138
|
end
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
superclass = Type::Builtin[:obj]
|
1149
|
-
elsif superclass.is_a?(Type::Instance)
|
1150
|
-
warn(ep, "superclass is an instance; Object is used instead")
|
1151
|
-
superclass = Type::Builtin[:obj]
|
1152
|
-
else
|
1153
|
-
warn(ep, "superclass is not a class; Object is used instead")
|
1154
|
-
superclass = Type::Builtin[:obj]
|
1155
|
-
end
|
1156
|
-
else # module
|
1157
|
-
superclass = nil
|
1158
|
-
end
|
1159
|
-
if cbase == Type.any
|
1160
|
-
klass = Type.any
|
1139
|
+
if type == :class
|
1140
|
+
if superclass.is_a?(Type::Class)
|
1141
|
+
# okay
|
1142
|
+
elsif superclass == Type.any
|
1143
|
+
warn(ep, "superclass is any; Object is used instead")
|
1144
|
+
superclass = Type::Builtin[:obj]
|
1145
|
+
elsif superclass == Type.nil
|
1146
|
+
superclass = Type::Builtin[:obj]
|
1147
|
+
elsif superclass.is_a?(Type::Instance)
|
1148
|
+
warn(ep, "superclass is an instance; Object is used instead")
|
1149
|
+
superclass = Type::Builtin[:obj]
|
1161
1150
|
else
|
1162
|
-
|
1151
|
+
warn(ep, "superclass is not a class; Object is used instead")
|
1152
|
+
superclass = Type::Builtin[:obj]
|
1163
1153
|
end
|
1154
|
+
else # module
|
1155
|
+
superclass = nil
|
1156
|
+
end
|
1157
|
+
if cbase == Type.any
|
1158
|
+
klass = Type.any
|
1159
|
+
else
|
1160
|
+
klass = new_class(cbase, id, [], superclass, ep.ctx.iseq.absolute_path)
|
1164
1161
|
end
|
1165
1162
|
end
|
1166
1163
|
singleton = false
|
@@ -306,6 +306,9 @@ module TypeProf
|
|
306
306
|
|
307
307
|
def screen_name(scratch)
|
308
308
|
if Config.options[:show_container_raw_elements] || @rest_ty == Type.bot
|
309
|
+
if @lead_tys.empty?
|
310
|
+
return "Array[bot]" # RBS does not allow an empty tuple "[]"
|
311
|
+
end
|
309
312
|
s = @lead_tys.map do |ty|
|
310
313
|
ty.screen_name(scratch)
|
311
314
|
end
|
@@ -631,16 +634,22 @@ module TypeProf
|
|
631
634
|
end
|
632
635
|
|
633
636
|
def screen_name(scratch)
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
+
if !@map_tys.empty? && @map_tys.all? {|k_ty,| k_ty.is_a?(Type::Symbol) }
|
638
|
+
s = @map_tys.map do |k_ty, v_ty|
|
639
|
+
v = v_ty.screen_name(scratch)
|
637
640
|
"#{ k_ty.sym }: #{ v }"
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
+
end.join(", ")
|
642
|
+
"{#{ s }}"
|
643
|
+
else
|
644
|
+
k_ty = v_ty = Type.bot
|
645
|
+
@map_tys.each do |k, v|
|
646
|
+
k_ty = k_ty.union(k)
|
647
|
+
v_ty = v_ty.union(v)
|
641
648
|
end
|
642
|
-
|
643
|
-
|
649
|
+
k_ty = k_ty.screen_name(scratch)
|
650
|
+
v_ty = v_ty.screen_name(scratch)
|
651
|
+
"Hash[#{ k_ty }, #{ v_ty }]"
|
652
|
+
end
|
644
653
|
end
|
645
654
|
|
646
655
|
def pretty_print(q)
|
data/lib/typeprof/type.rb
CHANGED
@@ -449,7 +449,7 @@ module TypeProf
|
|
449
449
|
end
|
450
450
|
|
451
451
|
def screen_name(scratch)
|
452
|
-
"#{ scratch.get_class_name(self) }
|
452
|
+
"singleton(#{ scratch.get_class_name(self) })"
|
453
453
|
end
|
454
454
|
|
455
455
|
def get_method(mid, scratch)
|
@@ -785,6 +785,10 @@ module TypeProf
|
|
785
785
|
end
|
786
786
|
str = str.empty? ? "" : "(#{ str.join(", ") })"
|
787
787
|
|
788
|
+
# Dirty Hack: Stop the iteration at most once!
|
789
|
+
# I'll remove this hack if RBS removes the limitation of nesting blocks
|
790
|
+
return str if caller_locations.any? {|frame| frame.label == "show_block_signature" }
|
791
|
+
|
788
792
|
optional = false
|
789
793
|
blks = []
|
790
794
|
@blk_ty.each_child_global do |ty|
|
data/lib/typeprof/version.rb
CHANGED
data/smoke/array11.rb
CHANGED
@@ -9,5 +9,5 @@ array("foo")
|
|
9
9
|
__END__
|
10
10
|
# Classes
|
11
11
|
class Object
|
12
|
-
def array : (Array[Integer] |
|
12
|
+
def array : (Array[Integer] | Hash[Integer, Integer] | String) -> (Array[Hash[Integer, Integer] | Integer | String])
|
13
13
|
end
|
data/smoke/array6.rb
CHANGED
data/smoke/array8.rb
CHANGED
data/smoke/block-args2.rb
CHANGED
@@ -47,11 +47,11 @@ __END__
|
|
47
47
|
# Classes
|
48
48
|
class Object
|
49
49
|
def f1 : { -> nil } -> ^(nil, *bot, nil) -> nil
|
50
|
-
def log1 : (nil, [], nil) -> nil
|
50
|
+
def log1 : (nil, Array[bot], nil) -> nil
|
51
51
|
def f2 : { (:a) -> nil } -> ^(:a, *bot, nil) -> nil
|
52
|
-
def log2 : (:a, [], nil) -> nil
|
52
|
+
def log2 : (:a, Array[bot], nil) -> nil
|
53
53
|
def f3 : { (:a, :b) -> nil } -> ^(:a, *bot, :b) -> nil
|
54
|
-
def log3 : (:a, [], :b) -> nil
|
54
|
+
def log3 : (:a, Array[bot], :b) -> nil
|
55
55
|
def f4 : { (:a, :b, :c) -> nil } -> ^(:a, *:b, :c) -> nil
|
56
56
|
def log4 : (:a, [:b], :c) -> nil
|
57
57
|
def f5 : { (:a, :b, :c, :d) -> nil } -> (^(:a, *:b | :c, :d) -> nil)
|
data/smoke/block-args3.rb
CHANGED
@@ -56,13 +56,13 @@ __END__
|
|
56
56
|
# Classes
|
57
57
|
class Object
|
58
58
|
def f1 : { -> nil } -> ^(nil, ?:opt, *bot, nil) -> nil
|
59
|
-
def log1 : (nil, :opt, [], nil) -> nil
|
59
|
+
def log1 : (nil, :opt, Array[bot], nil) -> nil
|
60
60
|
def f2 : { (:a) -> nil } -> ^(:a, ?:opt, *bot, nil) -> nil
|
61
|
-
def log2 : (:a, :opt, [], nil) -> nil
|
61
|
+
def log2 : (:a, :opt, Array[bot], nil) -> nil
|
62
62
|
def f3 : { (:a, :b) -> nil } -> ^(:a, ?:opt, *bot, :b) -> nil
|
63
|
-
def log3 : (:a, :opt, [], :b) -> nil
|
63
|
+
def log3 : (:a, :opt, Array[bot], :b) -> nil
|
64
64
|
def f4 : { (:a, :b, :c) -> nil } -> (^(:a, ?:b | :opt, *bot, :c) -> nil)
|
65
|
-
def log4 : (:a, :b | :opt, [], :c) -> nil
|
65
|
+
def log4 : (:a, :b | :opt, Array[bot], :c) -> nil
|
66
66
|
def f5 : { (:a, :b, :c, :d) -> nil } -> (^(:a, ?:b | :opt, *:c, :d) -> nil)
|
67
67
|
def log5 : (:a, :b | :opt, [:c], :d) -> nil
|
68
68
|
def f6 : { (:a, :b, :c, :d, :e) -> nil } -> (^(:a, ?:b | :opt, *:c | :d, :e) -> nil)
|
data/smoke/block-blockarg.rb
CHANGED
data/smoke/block5.rb
CHANGED
data/smoke/constant2.rb
CHANGED
@@ -24,12 +24,11 @@ smoke/constant2.rb:15: [warning] already initialized constant Object::BAR
|
|
24
24
|
|
25
25
|
# Classes
|
26
26
|
class Object
|
27
|
-
C : String
|
28
27
|
BAR : String
|
29
28
|
def foo : (Integer | untyped) -> nil
|
30
29
|
def log : (String) -> nil
|
31
30
|
end
|
32
31
|
|
33
|
-
class C
|
32
|
+
class C
|
34
33
|
def foo : -> nil
|
35
34
|
end
|
data/smoke/demo5.rb
CHANGED
data/smoke/demo9.rb
CHANGED
data/smoke/hash1.rb
CHANGED
@@ -5,6 +5,7 @@ end
|
|
5
5
|
foo
|
6
6
|
|
7
7
|
def bar
|
8
|
+
# This returns {Integer=>Integer | String, String=>String} but RBS cannot express it
|
8
9
|
{ 1 => 1, 2 => "str", "s" => "s" }
|
9
10
|
end
|
10
11
|
|
@@ -14,5 +15,5 @@ __END__
|
|
14
15
|
# Classes
|
15
16
|
class Object
|
16
17
|
def foo : -> {int: Integer, str: String}
|
17
|
-
def bar : -> (
|
18
|
+
def bar : -> (Hash[Integer | String, Integer | String])
|
18
19
|
end
|
data/smoke/hash4.rb
CHANGED
data/smoke/inheritance2.rb
CHANGED
@@ -21,11 +21,11 @@ end
|
|
21
21
|
__END__
|
22
22
|
# Classes
|
23
23
|
class SuperBase
|
24
|
-
def self.foo : -> (A
|
24
|
+
def self.foo : -> (singleton(A) | singleton(B))
|
25
25
|
end
|
26
26
|
|
27
27
|
class Base < SuperBase
|
28
|
-
def self.foo : -> (A
|
28
|
+
def self.foo : -> (singleton(A) | singleton(B))
|
29
29
|
end
|
30
30
|
|
31
31
|
class A < Base
|
data/smoke/ivar2.rb
CHANGED
data/smoke/kernel-class.rb
CHANGED
data/smoke/kwsplat1.rb
CHANGED
data/smoke/struct.rb
CHANGED
data/smoke/union-recv.rb
CHANGED
@@ -21,11 +21,11 @@ end
|
|
21
21
|
__END__
|
22
22
|
# Classes
|
23
23
|
class SuperBase
|
24
|
-
def self.foo : -> (A
|
24
|
+
def self.foo : -> (singleton(A) | singleton(B))
|
25
25
|
end
|
26
26
|
|
27
27
|
class Base < SuperBase
|
28
|
-
def self.foo : -> (A
|
28
|
+
def self.foo : -> (singleton(A) | singleton(B))
|
29
29
|
end
|
30
30
|
|
31
31
|
class A < Base
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typeprof
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yusuke Endoh
|
@@ -334,7 +334,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
334
334
|
- !ruby/object:Gem::Version
|
335
335
|
version: '0'
|
336
336
|
requirements: []
|
337
|
-
rubygems_version: 3.
|
337
|
+
rubygems_version: 3.1.4
|
338
338
|
signing_key:
|
339
339
|
specification_version: 4
|
340
340
|
summary: TypeProf is a type analysis tool for Ruby code based on abstract interpretation
|