typeprof 0.5.1 → 0.6.1
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 +145 -113
- data/lib/typeprof/builtin.rb +23 -8
- data/lib/typeprof/config.rb +10 -6
- data/lib/typeprof/container-type.rb +26 -17
- data/lib/typeprof/export.rb +6 -6
- data/lib/typeprof/import.rb +67 -32
- data/lib/typeprof/method.rb +32 -15
- data/lib/typeprof/type.rb +20 -14
- 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/parameterizedd-self2.rb +15 -0
- data/smoke/rbs-tyvar6.rb +17 -0
- data/smoke/rbs-tyvar6.rbs +12 -0
- data/smoke/struct.rb +2 -2
- data/smoke/super4.rb +43 -0
- data/smoke/super5.rb +36 -0
- data/smoke/union-recv.rb +2 -2
- metadata +7 -2
data/lib/typeprof/type.rb
CHANGED
@@ -170,7 +170,7 @@ module TypeProf
|
|
170
170
|
"untyped"
|
171
171
|
end
|
172
172
|
|
173
|
-
def
|
173
|
+
def method_dispatch_info
|
174
174
|
nil
|
175
175
|
end
|
176
176
|
|
@@ -430,15 +430,17 @@ module TypeProf
|
|
430
430
|
end
|
431
431
|
|
432
432
|
class Class < Type # or Module
|
433
|
-
def initialize(kind, idx, type_params, superclass, name)
|
433
|
+
def initialize(kind, idx, type_params, superclass, superclass_type_args, name)
|
434
434
|
@kind = kind # :class | :module
|
435
435
|
@idx = idx
|
436
436
|
@type_params = type_params
|
437
437
|
@superclass = superclass
|
438
|
+
raise if @kind == :class && !@superclass
|
439
|
+
@superclass_type_args = superclass_type_args
|
438
440
|
@_name = name
|
439
441
|
end
|
440
442
|
|
441
|
-
attr_reader :kind, :idx, :type_params, :superclass
|
443
|
+
attr_reader :kind, :idx, :type_params, :superclass, :superclass_type_args
|
442
444
|
|
443
445
|
def inspect
|
444
446
|
if @_name
|
@@ -449,11 +451,11 @@ module TypeProf
|
|
449
451
|
end
|
450
452
|
|
451
453
|
def screen_name(scratch)
|
452
|
-
"#{ scratch.get_class_name(self) }
|
454
|
+
"singleton(#{ scratch.get_class_name(self) })"
|
453
455
|
end
|
454
456
|
|
455
|
-
def
|
456
|
-
|
457
|
+
def method_dispatch_info
|
458
|
+
[self, true]
|
457
459
|
end
|
458
460
|
|
459
461
|
def consistent?(other)
|
@@ -504,8 +506,8 @@ module TypeProf
|
|
504
506
|
end
|
505
507
|
end
|
506
508
|
|
507
|
-
def
|
508
|
-
|
509
|
+
def method_dispatch_info
|
510
|
+
[@klass, false]
|
509
511
|
end
|
510
512
|
|
511
513
|
def consistent?(other)
|
@@ -558,8 +560,8 @@ module TypeProf
|
|
558
560
|
end
|
559
561
|
end
|
560
562
|
|
561
|
-
def
|
562
|
-
@base_type.
|
563
|
+
def method_dispatch_info
|
564
|
+
@base_type.method_dispatch_info
|
563
565
|
end
|
564
566
|
|
565
567
|
def substitute(subst, depth)
|
@@ -600,8 +602,8 @@ module TypeProf
|
|
600
602
|
end
|
601
603
|
end
|
602
604
|
|
603
|
-
def
|
604
|
-
@base_type.
|
605
|
+
def method_dispatch_info
|
606
|
+
@base_type.method_dispatch_info
|
605
607
|
end
|
606
608
|
|
607
609
|
def substitute(_subst, _depth)
|
@@ -630,8 +632,8 @@ module TypeProf
|
|
630
632
|
@base_type
|
631
633
|
end
|
632
634
|
|
633
|
-
def
|
634
|
-
@base_type.
|
635
|
+
def method_dispatch_info
|
636
|
+
@base_type.method_dispatch_info
|
635
637
|
end
|
636
638
|
|
637
639
|
def consistent?(_other)
|
@@ -785,6 +787,10 @@ module TypeProf
|
|
785
787
|
end
|
786
788
|
str = str.empty? ? "" : "(#{ str.join(", ") })"
|
787
789
|
|
790
|
+
# Dirty Hack: Stop the iteration at most once!
|
791
|
+
# I'll remove this hack if RBS removes the limitation of nesting blocks
|
792
|
+
return str if caller_locations.any? {|frame| frame.label == "show_block_signature" }
|
793
|
+
|
788
794
|
optional = false
|
789
795
|
blks = []
|
790
796
|
@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
@@ -0,0 +1,15 @@
|
|
1
|
+
class Object
|
2
|
+
def foo
|
3
|
+
# The receiver is considered as an empty array
|
4
|
+
self[0]
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
# The elements are dropped when it is passed as a receiver (to avoid state explosion)
|
9
|
+
[0].foo
|
10
|
+
|
11
|
+
__END__
|
12
|
+
# Classes
|
13
|
+
class Object
|
14
|
+
def foo : -> nil
|
15
|
+
end
|
data/smoke/rbs-tyvar6.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
def log1(obj) end
|
2
|
+
def log2(obj) end
|
3
|
+
def log3(obj) end
|
4
|
+
|
5
|
+
obj = Bar.new("str")
|
6
|
+
|
7
|
+
log1(obj)
|
8
|
+
log2(obj.test_superclass)
|
9
|
+
log3(obj.test_module)
|
10
|
+
|
11
|
+
__END__
|
12
|
+
# Classes
|
13
|
+
class Object
|
14
|
+
def log1 : (Bar[String]) -> nil
|
15
|
+
def log2 : (Array[String]) -> nil
|
16
|
+
def log3 : (Integer) -> nil
|
17
|
+
end
|
data/smoke/struct.rb
CHANGED
data/smoke/super4.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module M1
|
2
|
+
def f(m); super :M1; end
|
3
|
+
end
|
4
|
+
module M2
|
5
|
+
def f(m); super :M2; end
|
6
|
+
end
|
7
|
+
class C
|
8
|
+
def f(m); end
|
9
|
+
end
|
10
|
+
class D < C
|
11
|
+
def f(m); super :D; end
|
12
|
+
include M1
|
13
|
+
end
|
14
|
+
class E < D
|
15
|
+
def f(m); super :E; end
|
16
|
+
include M2
|
17
|
+
end
|
18
|
+
|
19
|
+
E.new.f(:top)
|
20
|
+
|
21
|
+
__END__
|
22
|
+
# Classes
|
23
|
+
module M1
|
24
|
+
def f : (:D) -> nil
|
25
|
+
end
|
26
|
+
|
27
|
+
module M2
|
28
|
+
def f : (:E) -> nil
|
29
|
+
end
|
30
|
+
|
31
|
+
class C
|
32
|
+
def f : (:M1) -> nil
|
33
|
+
end
|
34
|
+
|
35
|
+
class D < C
|
36
|
+
include M1
|
37
|
+
def f : (:M2) -> nil
|
38
|
+
end
|
39
|
+
|
40
|
+
class E < D
|
41
|
+
include M2
|
42
|
+
def f : (:top) -> nil
|
43
|
+
end
|
data/smoke/super5.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module M
|
2
|
+
def f(m); super :M; end
|
3
|
+
end
|
4
|
+
class C
|
5
|
+
def f(m); end
|
6
|
+
end
|
7
|
+
class D < C
|
8
|
+
def f(m); super :D; end
|
9
|
+
include M
|
10
|
+
end
|
11
|
+
class E < D
|
12
|
+
def f(m); super :E; end
|
13
|
+
include M
|
14
|
+
end
|
15
|
+
|
16
|
+
E.new.f(:top)
|
17
|
+
|
18
|
+
__END__
|
19
|
+
# Classes
|
20
|
+
module M
|
21
|
+
def f : (:D | :E) -> nil
|
22
|
+
end
|
23
|
+
|
24
|
+
class C
|
25
|
+
def f : (:M) -> nil
|
26
|
+
end
|
27
|
+
|
28
|
+
class D < C
|
29
|
+
include M
|
30
|
+
def f : (:M) -> nil
|
31
|
+
end
|
32
|
+
|
33
|
+
class E < D
|
34
|
+
include M
|
35
|
+
def f : (:top) -> nil
|
36
|
+
end
|
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
|