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.
@@ -170,7 +170,7 @@ module TypeProf
170
170
  "untyped"
171
171
  end
172
172
 
173
- def get_method(mid, scratch)
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) }.class"
454
+ "singleton(#{ scratch.get_class_name(self) })"
453
455
  end
454
456
 
455
- def get_method(mid, scratch)
456
- scratch.get_method(self, true, mid)
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 get_method(mid, scratch)
508
- scratch.get_method(@klass, false, mid)
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 get_method(mid, scratch)
562
- @base_type.get_method(mid, scratch)
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 get_method(mid, scratch)
604
- @base_type.get_method(mid, scratch)
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 get_method(mid, scratch)
634
- @base_type.get_method(mid, scratch)
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|
@@ -1,3 +1,3 @@
1
1
  module TypeProf
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.1"
3
3
  end
@@ -9,5 +9,5 @@ array("foo")
9
9
  __END__
10
10
  # Classes
11
11
  class Object
12
- def array : (Array[Integer] | String | {Integer=>Integer}) -> (Array[Integer | String | {Integer=>Integer}])
12
+ def array : (Array[Integer] | Hash[Integer, Integer] | String) -> (Array[Hash[Integer, Integer] | Integer | String])
13
13
  end
@@ -10,6 +10,6 @@ foo(1, "str")
10
10
  __END__
11
11
  # Classes
12
12
  class Object
13
- ARY : []
14
- def foo : (Integer, String) -> []
13
+ ARY : Array[bot]
14
+ def foo : (Integer, String) -> Array[bot]
15
15
  end
@@ -9,5 +9,5 @@ end
9
9
  __END__
10
10
  # Classes
11
11
  class Foo
12
- def self.foo : ([]) -> []
12
+ def self.foo : (Array[bot]) -> Array[bot]
13
13
  end
@@ -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)
@@ -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)
@@ -23,5 +23,5 @@ class Object
23
23
  def log1 : (:a) -> nil
24
24
  def log2 : (:b) -> nil
25
25
  def log3 : (:c) -> nil
26
- def f : { { (:a) -> :b } -> :c } -> :d
26
+ def f : { -> :c } -> :d
27
27
  end
@@ -15,5 +15,5 @@ __END__
15
15
  # Classes
16
16
  class Object
17
17
  F : ^(Integer) -> String
18
- def foo : { (:sym) { (Integer) -> String } -> String } -> String
18
+ def foo : { (:sym) -> String } -> String
19
19
  end
@@ -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(dummy)
32
+ class C
34
33
  def foo : -> nil
35
34
  end
@@ -9,7 +9,7 @@ B.foo(Integer)
9
9
  __END__
10
10
  # Classes
11
11
  class A
12
- def self.foo : (Integer | Integer.class) -> String
12
+ def self.foo : (Integer | singleton(Integer)) -> String
13
13
  end
14
14
 
15
15
  class B < A
@@ -12,5 +12,5 @@ __END__
12
12
  # Classes
13
13
  class Object
14
14
  F : ^(Integer) -> String
15
- def foo : { (:sym) { (Integer) -> String } -> String } -> String
15
+ def foo : { (:sym) -> String } -> String
16
16
  end
@@ -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 : -> ({Integer=>Integer | String, String=>String})
18
+ def bar : -> (Hash[Integer | String, Integer | String])
18
19
  end
@@ -6,5 +6,5 @@ foo
6
6
  __END__
7
7
  # Classes
8
8
  class Object
9
- def foo : -> {}
9
+ def foo : -> Hash[bot, bot]
10
10
  end
@@ -21,11 +21,11 @@ end
21
21
  __END__
22
22
  # Classes
23
23
  class SuperBase
24
- def self.foo : -> (A.class | B.class)
24
+ def self.foo : -> (singleton(A) | singleton(B))
25
25
  end
26
26
 
27
27
  class Base < SuperBase
28
- def self.foo : -> (A.class | B.class)
28
+ def self.foo : -> (singleton(A) | singleton(B))
29
29
  end
30
30
 
31
31
  class A < Base
@@ -25,6 +25,6 @@ __END__
25
25
  class Foo
26
26
  attr_reader array : Array[:sym | Integer | String]
27
27
  attr_reader hash : {a: Integer, b: String, c: :sym}
28
- def initialize : -> {}
28
+ def initialize : -> Hash[bot, bot]
29
29
  def set : -> :sym
30
30
  end
@@ -8,5 +8,5 @@ foo("")
8
8
  __END__
9
9
  # Classes
10
10
  class Object
11
- def foo : (Integer | String) -> (Integer.class | String.class)
11
+ def foo : (Integer | String) -> (singleton(Integer) | singleton(String))
12
12
  end
@@ -38,5 +38,5 @@ class Object
38
38
  def foo : (k: Integer) -> nil
39
39
  def bar : (int: Integer, str: String) -> nil
40
40
  def baz : (**{int: Integer, str: String}) -> nil
41
- def qux : (**{untyped=>untyped}) -> nil
41
+ def qux : (**Hash[untyped, untyped]) -> nil
42
42
  end
@@ -15,7 +15,7 @@ smoke/multiple-superclass.rb:9: [warning] superclass is not a class; Object is u
15
15
 
16
16
  # Classes
17
17
  class Object
18
- Base : A.class | B.class
18
+ Base : singleton(A) | singleton(B)
19
19
  end
20
20
 
21
21
  class A
@@ -13,6 +13,6 @@ bar([])
13
13
  __END__
14
14
  # Classes
15
15
  class Object
16
- def foo : -> []
17
- def bar : ([]) -> []
16
+ def foo : -> Array[bot]
17
+ def bar : (Array[bot]) -> Array[bot]
18
18
  end
@@ -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
@@ -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
@@ -0,0 +1,12 @@
1
+ class Foo[X]
2
+ def test_superclass: -> X
3
+ end
4
+
5
+ module M[X]
6
+ def test_module: -> X
7
+ end
8
+
9
+ class Bar[X] < Foo[Array[X]]
10
+ def initialize: (X) -> void
11
+ include M[Integer]
12
+ end
@@ -5,9 +5,9 @@ end
5
5
  Foo.new.a = 1
6
6
  __END__
7
7
  # Classes
8
- class (Anonymous Struct) < Struct
8
+ class AnonymousStruct_generated_1 < Struct
9
9
  attr_accessor a() : untyped
10
10
  end
11
11
 
12
- class Foo < (Anonymous Struct)
12
+ class Foo < AnonymousStruct_generated_1
13
13
  end
@@ -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
@@ -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
@@ -21,11 +21,11 @@ end
21
21
  __END__
22
22
  # Classes
23
23
  class SuperBase
24
- def self.foo : -> (A.class | B.class)
24
+ def self.foo : -> (singleton(A) | singleton(B))
25
25
  end
26
26
 
27
27
  class Base < SuperBase
28
- def self.foo : -> (A.class | B.class)
28
+ def self.foo : -> (singleton(A) | singleton(B))
29
29
  end
30
30
 
31
31
  class A < Base