typeprof 0.2.0 → 0.5.0
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/.github/workflows/main.yml +1 -2
- data/.gitignore +1 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +10 -21
- data/LICENSE +21 -0
- data/README.md +6 -0
- data/doc/demo.md +398 -0
- data/doc/doc.ja.md +6 -1
- data/doc/doc.md +7 -2
- data/exe/typeprof +2 -1
- data/lib/typeprof.rb +9 -0
- data/lib/typeprof/analyzer.rb +427 -325
- data/lib/typeprof/arguments.rb +405 -0
- data/lib/typeprof/block.rb +136 -0
- data/lib/typeprof/builtin.rb +36 -25
- data/lib/typeprof/cli.rb +51 -98
- data/lib/typeprof/config.rb +114 -0
- data/lib/typeprof/container-type.rb +280 -92
- data/lib/typeprof/export.rb +197 -108
- data/lib/typeprof/import.rb +134 -80
- data/lib/typeprof/iseq.rb +42 -1
- data/lib/typeprof/method.rb +178 -82
- data/lib/typeprof/type.rb +228 -369
- data/lib/typeprof/utils.rb +4 -18
- data/lib/typeprof/version.rb +3 -0
- data/smoke/arguments2.rb +55 -0
- data/smoke/array-each3.rb +1 -4
- data/smoke/array12.rb +1 -1
- data/smoke/array6.rb +1 -0
- data/smoke/block-ambiguous.rb +36 -0
- data/smoke/block-args1-rest.rb +62 -0
- data/smoke/block-args1.rb +59 -0
- data/smoke/block-args2-rest.rb +62 -0
- data/smoke/block-args2.rb +59 -0
- data/smoke/block-args3-rest.rb +73 -0
- data/smoke/block-args3.rb +70 -0
- data/smoke/block-blockarg.rb +27 -0
- data/smoke/block-kwarg.rb +52 -0
- data/smoke/block10.rb +1 -1
- data/smoke/block11.rb +1 -1
- data/smoke/block14.rb +17 -0
- data/smoke/block4.rb +2 -2
- data/smoke/block5.rb +1 -0
- data/smoke/block6.rb +1 -1
- data/smoke/block7.rb +0 -2
- data/smoke/block8.rb +2 -2
- data/smoke/block9.rb +1 -1
- data/smoke/blown.rb +1 -1
- data/smoke/class-hierarchy.rb +54 -0
- data/smoke/class-hierarchy2.rb +27 -0
- data/smoke/constant1.rb +11 -6
- data/smoke/constant2.rb +2 -0
- data/smoke/cvar.rb +1 -0
- data/smoke/demo10.rb +1 -1
- data/smoke/demo8.rb +2 -2
- data/smoke/demo9.rb +1 -3
- data/smoke/flow7.rb +1 -7
- data/smoke/flow8.rb +13 -0
- data/smoke/hash-fetch.rb +3 -3
- data/smoke/hash-merge-bang.rb +11 -0
- data/smoke/hash1.rb +1 -1
- data/smoke/hash3.rb +1 -1
- data/smoke/hash4.rb +1 -1
- data/smoke/instance_eval.rb +1 -1
- data/smoke/int_times.rb +1 -1
- data/smoke/ivar2.rb +1 -1
- data/smoke/keyword3.rb +1 -2
- data/smoke/keyword4.rb +1 -1
- data/smoke/kwsplat1.rb +1 -1
- data/smoke/kwsplat2.rb +1 -1
- data/smoke/module4.rb +2 -0
- data/smoke/multiple-superclass.rb +4 -0
- data/smoke/next2.rb +1 -1
- data/smoke/optional1.rb +1 -1
- data/smoke/optional2.rb +1 -1
- data/smoke/optional3.rb +10 -0
- data/smoke/pattern-match1.rb +23 -0
- data/smoke/pattern-match2.rb +15 -0
- data/smoke/proc4.rb +1 -1
- data/smoke/rbs-extend.rb +9 -0
- data/smoke/rbs-extend.rbs +7 -0
- data/smoke/rbs-interface.rb +24 -0
- data/smoke/rbs-interface.rbs +12 -0
- data/smoke/rbs-proc1.rb +9 -0
- data/smoke/rbs-proc1.rbs +3 -0
- data/smoke/rbs-proc2.rb +20 -0
- data/smoke/rbs-proc2.rbs +3 -0
- data/smoke/rbs-proc3.rb +13 -0
- data/smoke/rbs-proc3.rbs +4 -0
- data/smoke/rbs-record.rb +17 -0
- data/smoke/rbs-record.rbs +4 -0
- data/smoke/rbs-tyvar.rb +18 -0
- data/smoke/rbs-tyvar.rbs +5 -0
- data/smoke/rbs-tyvar2.rb +20 -0
- data/smoke/rbs-tyvar2.rbs +9 -0
- data/smoke/rbs-tyvar3.rb +17 -0
- data/smoke/rbs-tyvar3.rbs +5 -0
- data/smoke/rbs-tyvar4.rb +36 -0
- data/smoke/rbs-tyvar5.rb +12 -0
- data/smoke/rbs-tyvar5.rbs +8 -0
- data/smoke/rest1.rb +1 -1
- data/smoke/rest2.rb +1 -1
- data/smoke/rest3.rb +1 -1
- data/smoke/rest5.rb +1 -1
- data/smoke/rest6.rb +1 -1
- data/smoke/retry1.rb +1 -1
- data/smoke/return.rb +1 -1
- data/smoke/singleton_method.rb +3 -0
- data/smoke/step.rb +1 -1
- data/smoke/struct.rb +4 -3
- data/smoke/struct3.rb +14 -0
- data/smoke/symbol-proc.rb +24 -0
- data/smoke/uninitialize-var.rb +12 -0
- data/smoke/user-demo.rb +15 -0
- data/smoke/wrong-extend.rb +1 -0
- data/typeprof.gemspec +4 -2
- metadata +53 -6
- data/run.sh +0 -3
- data/smoke/variadic1.rb.notyet +0 -5
data/smoke/hash1.rb
CHANGED
data/smoke/hash3.rb
CHANGED
data/smoke/hash4.rb
CHANGED
data/smoke/instance_eval.rb
CHANGED
data/smoke/int_times.rb
CHANGED
data/smoke/ivar2.rb
CHANGED
data/smoke/keyword3.rb
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
# TODO: foo should accept "s: String | [Integer]"?
|
|
2
1
|
def foo(n: 42, s: [n])
|
|
3
2
|
[n, s]
|
|
4
3
|
end
|
|
@@ -8,5 +7,5 @@ foo(n: 42, s: "str")
|
|
|
8
7
|
__END__
|
|
9
8
|
# Classes
|
|
10
9
|
class Object
|
|
11
|
-
def foo : (?n: Integer, ?s: String) -> ([Integer, String | [Integer]])
|
|
10
|
+
def foo : (?n: Integer, ?s: String | [Integer]) -> ([Integer, String | [Integer]])
|
|
12
11
|
end
|
data/smoke/keyword4.rb
CHANGED
data/smoke/kwsplat1.rb
CHANGED
|
@@ -37,6 +37,6 @@ smoke/kwsplat1.rb:30: [error] undefined method: Object#any
|
|
|
37
37
|
class Object
|
|
38
38
|
def foo : (k: Integer) -> nil
|
|
39
39
|
def bar : (int: Integer, str: String) -> nil
|
|
40
|
-
def baz : (**{:
|
|
40
|
+
def baz : (**{int: Integer, str: String}) -> nil
|
|
41
41
|
def qux : (**{untyped=>untyped}) -> nil
|
|
42
42
|
end
|
data/smoke/kwsplat2.rb
CHANGED
data/smoke/module4.rb
CHANGED
data/smoke/next2.rb
CHANGED
data/smoke/optional1.rb
CHANGED
|
@@ -9,5 +9,5 @@ foo("A", "B", "C", "Z")
|
|
|
9
9
|
__END__
|
|
10
10
|
# Classes
|
|
11
11
|
class Object
|
|
12
|
-
def foo : (String, ?String, ?String, String) -> ([String, Integer | String, Integer | String, String])
|
|
12
|
+
def foo : (String, ?Integer | String, ?Integer | String, String) -> ([String, Integer | String, Integer | String, String])
|
|
13
13
|
end
|
data/smoke/optional2.rb
CHANGED
|
@@ -11,5 +11,5 @@ foo("A", "B", "C", "D", "E", "Z")
|
|
|
11
11
|
__END__
|
|
12
12
|
# Classes
|
|
13
13
|
class Object
|
|
14
|
-
def foo : (String, ?String, ?String, *String, String) -> ([String, Integer | String, Integer | String, Array[String], String])
|
|
14
|
+
def foo : (String, ?Integer | String, ?Integer | String, *String, String) -> ([String, Integer | String, Integer | String, Array[String], String])
|
|
15
15
|
end
|
data/smoke/optional3.rb
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# RUBY_VERSION >= 3.0
|
|
2
|
+
|
|
3
|
+
def foo
|
|
4
|
+
case [:a, :b, :c]
|
|
5
|
+
in [a, b, :c]
|
|
6
|
+
# Due to very subtle detail of bytecode, the variables "a" and "b" could be nil
|
|
7
|
+
return a, b
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
foo
|
|
12
|
+
|
|
13
|
+
__END__
|
|
14
|
+
# Errors
|
|
15
|
+
smoke/pattern-match1.rb:5: [error] undefined method: nil#length
|
|
16
|
+
smoke/pattern-match1.rb:5: [error] undefined method: nil#[]
|
|
17
|
+
smoke/pattern-match1.rb:5: [error] undefined method: nil#[]
|
|
18
|
+
smoke/pattern-match1.rb:5: [error] undefined method: nil#[]
|
|
19
|
+
|
|
20
|
+
# Classes
|
|
21
|
+
class Object
|
|
22
|
+
def foo : -> ([:a | untyped, :b | untyped])
|
|
23
|
+
end
|
data/smoke/proc4.rb
CHANGED
data/smoke/rbs-extend.rb
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
def get_module
|
|
2
|
+
C.new.get_module
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
def get_module_foo
|
|
6
|
+
C.new.get_module.foo
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def get_interface
|
|
10
|
+
C.new.get_interface
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def get_interface_foo
|
|
14
|
+
C.new.get_interface.foo
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
__END__
|
|
18
|
+
# Classes
|
|
19
|
+
class Object
|
|
20
|
+
def get_module : -> M
|
|
21
|
+
def get_module_foo : -> Integer
|
|
22
|
+
def get_interface : -> _I
|
|
23
|
+
def get_interface_foo : -> Integer
|
|
24
|
+
end
|
data/smoke/rbs-proc1.rb
ADDED
data/smoke/rbs-proc1.rbs
ADDED
data/smoke/rbs-proc2.rb
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# two issues:
|
|
2
|
+
# (1) TypedProc should call `-> n { log1(n) }` with an Integer, but not implemented yet
|
|
3
|
+
# (2) log1 returns a String, which is inconsistent and should be reported
|
|
4
|
+
|
|
5
|
+
def log1(n)
|
|
6
|
+
n.to_s # XXX: should be reported as "inconsistent with RBS"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def log2
|
|
10
|
+
Foo.new.foo(-> n { log1(n) })
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
log2
|
|
14
|
+
|
|
15
|
+
__END__
|
|
16
|
+
# Classes
|
|
17
|
+
class Object
|
|
18
|
+
def log1 : (untyped) -> untyped
|
|
19
|
+
def log2 : -> String
|
|
20
|
+
end
|
data/smoke/rbs-proc2.rbs
ADDED
data/smoke/rbs-proc3.rb
ADDED
data/smoke/rbs-proc3.rbs
ADDED
data/smoke/rbs-record.rb
ADDED
data/smoke/rbs-tyvar.rb
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
def foo
|
|
2
|
+
cell = Cell.new("str")
|
|
3
|
+
cell.set_elem(42) if rand < 0.5
|
|
4
|
+
cell
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def bar
|
|
8
|
+
foo.get_elem
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
bar
|
|
12
|
+
|
|
13
|
+
__END__
|
|
14
|
+
# Classes
|
|
15
|
+
class Object
|
|
16
|
+
def foo : -> (Cell[Integer | String])
|
|
17
|
+
def bar : -> (Integer | String)
|
|
18
|
+
end
|
data/smoke/rbs-tyvar.rbs
ADDED
data/smoke/rbs-tyvar2.rb
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
def foo
|
|
2
|
+
cell = Cell.new(:a1, :b1, :c1)
|
|
3
|
+
cell.set_a(:a2)
|
|
4
|
+
cell.set_b(:b2)
|
|
5
|
+
cell.set_c(:c2)
|
|
6
|
+
cell
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def bar
|
|
10
|
+
foo.get_b
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
bar
|
|
14
|
+
|
|
15
|
+
__END__
|
|
16
|
+
# Classes
|
|
17
|
+
class Object
|
|
18
|
+
def foo : -> (Cell[:a1 | :a2, :b1 | :b2, :c1 | :c2])
|
|
19
|
+
def bar : -> (:b1 | :b2)
|
|
20
|
+
end
|
data/smoke/rbs-tyvar3.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
def foo
|
|
2
|
+
cell = Cell.new(42)
|
|
3
|
+
cell.map {|s| (s + 1).to_s }
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def bar
|
|
7
|
+
cell = Cell.new(42)
|
|
8
|
+
cell.map! {|s| (s + 1).to_s }
|
|
9
|
+
cell
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
__END__
|
|
13
|
+
# Classes
|
|
14
|
+
class Object
|
|
15
|
+
def foo : -> Cell[String]
|
|
16
|
+
def bar : -> (Cell[Integer | String])
|
|
17
|
+
end
|
data/smoke/rbs-tyvar4.rb
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# This code is created by simplifying matrix.rb.
|
|
2
|
+
# The issue occurs when `Array.new` creates a cell-type container,
|
|
3
|
+
# so this test will be obsolete, but keep it just for case of regression.
|
|
4
|
+
#
|
|
5
|
+
# https://github.com/ruby/typeprof/issues/14
|
|
6
|
+
|
|
7
|
+
class Foo
|
|
8
|
+
def initialize(ivar)
|
|
9
|
+
@ivar = ivar
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def foo(n)
|
|
13
|
+
@ivar.each_with_index { }
|
|
14
|
+
nil
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
Foo.new([])
|
|
19
|
+
|
|
20
|
+
rows = Array.new(1) do |i|
|
|
21
|
+
Array.new(1) do |j|
|
|
22
|
+
"str"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
obj = Foo.new(rows)
|
|
26
|
+
|
|
27
|
+
obj.foo(:a)
|
|
28
|
+
obj.foo(:b)
|
|
29
|
+
|
|
30
|
+
__END__
|
|
31
|
+
# Classes
|
|
32
|
+
class Foo
|
|
33
|
+
@ivar : Array[Array[String]]
|
|
34
|
+
def initialize : (Array[Array[String]]) -> Array[Array[String]]
|
|
35
|
+
def foo : (:a | :b) -> nil
|
|
36
|
+
end
|