typeprof 0.5.3 → 0.5.4

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: b1281ceb7a6a28b6dec33aad740d0fa52429a17ca29d57747717247fdb449c79
4
- data.tar.gz: 3ad79ab67ba6080e0c1da2b46671012e4db2f886020a11772158449ffd85717b
3
+ metadata.gz: 2d60066fe3965ec65f9885e311f856277d0e41330478489c026fdf6b387ba2ba
4
+ data.tar.gz: 963b66fe97d98207d72645011bcd012368937ded76278d92a4b677b961c92cdc
5
5
  SHA512:
6
- metadata.gz: c0e888c0c1cc871b23592f29d138f7c9c8ca5370fa98699c9b504aa29c79796f58d97653fac98cef2df1d8e7f5c961942ee28d385a95695e4ce7f1ff3c8d24f5
7
- data.tar.gz: 3ee4de72a8e26aed401b1879575ef82c0b1215fe9ccb87ee2c781a8138becc9ab948aea00e07e8e344ca4f96610ebfefdc540f175253cfe32dca1f721c232e7f
6
+ metadata.gz: a40e89e05c1680480eb66798863ab99a4b38b3faaacdc471a6cdd45dfc1f897efcc8f613800ef28e5bc722c3504dec510ca943435873b6cb765a27f1bb073425
7
+ data.tar.gz: 94dddf2c3e465ee19093ce571d50440293118b07ab7c90203aa5ccb40c4f9eb9afe1059eff045c965006affa8f0d66d141be2064feddf9a2b1f8384f8cadae64
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- typeprof (0.5.2)
4
+ typeprof (0.5.4)
5
5
  rbs (>= 0.17.0)
6
6
 
7
7
  GEM
@@ -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
- @class_defs[idx] = ClassDef.new(:class, ["(Anonymous Struct)"], superclass.idx, ep.ctx.iseq.absolute_path)
401
- klass = Type::Class.new(:class, idx, [], superclass, "(Anonymous Struct)")
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
- existing_klass = get_constant(cbase, id) # TODO: multiple return values
1138
- if existing_klass != Type.any
1139
- klass = existing_klass
1140
- else
1141
- if type == :class
1142
- if superclass.is_a?(Type::Class)
1143
- # okay
1144
- elsif superclass == Type.any
1145
- warn(ep, "superclass is any; Object is used instead")
1146
- superclass = Type::Builtin[:obj]
1147
- elsif superclass == Type.nil
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
- klass = new_class(cbase, id, [], superclass, ep.ctx.iseq.absolute_path)
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
- s = @map_tys.map do |k_ty, v_ty|
635
- v = v_ty.screen_name(scratch)
636
- if k_ty.is_a?(Type::Symbol)
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
- else
639
- k = k_ty.screen_name(scratch)
640
- "#{ k }=>#{ v }"
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
- end.join(", ")
643
- "{#{ s }}"
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)
@@ -449,7 +449,7 @@ module TypeProf
449
449
  end
450
450
 
451
451
  def screen_name(scratch)
452
- "#{ scratch.get_class_name(self) }.class"
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|
@@ -1,3 +1,3 @@
1
1
  module TypeProf
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.4"
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
@@ -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
@@ -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
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.3
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.2.0.rc.2
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