steep 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/bin/smoke_runner.rb +1 -1
- data/lib/steep.rb +6 -4
- data/lib/steep/ast/builtin.rb +96 -0
- data/lib/steep/ast/location.rb +9 -5
- data/lib/steep/ast/namespace.rb +80 -0
- data/lib/steep/ast/signature/env.rb +37 -31
- data/lib/steep/ast/types/boolean.rb +2 -2
- data/lib/steep/ast/types/hash.rb +50 -0
- data/lib/steep/ast/types/literal.rb +12 -10
- data/lib/steep/ast/types/name.rb +135 -94
- data/lib/steep/ast/types/nil.rb +3 -1
- data/lib/steep/ast/types/proc.rb +3 -1
- data/lib/steep/drivers/check.rb +4 -4
- data/lib/steep/drivers/utils/validator.rb +11 -16
- data/lib/steep/interface/builder.rb +201 -146
- data/lib/steep/interface/instantiated.rb +8 -0
- data/lib/steep/names.rb +86 -0
- data/lib/steep/parser.y +1093 -668
- data/lib/steep/source.rb +2 -2
- data/lib/steep/subtyping/check.rb +199 -63
- data/lib/steep/subtyping/constraints.rb +2 -5
- data/lib/steep/subtyping/variable_variance.rb +2 -2
- data/lib/steep/type_construction.rb +194 -175
- data/lib/steep/type_inference/block_params.rb +9 -21
- data/lib/steep/type_inference/constant_env.rb +26 -30
- data/lib/steep/type_inference/send_args.rb +4 -7
- data/lib/steep/type_inference/type_env.rb +3 -3
- data/lib/steep/version.rb +1 -1
- data/smoke/alias/a.rb +1 -1
- data/smoke/alias/b.rb +1 -1
- data/smoke/class/i.rbi +1 -1
- data/smoke/hash/a.rbi +8 -0
- data/smoke/hash/c.rb +18 -0
- data/smoke/hash/d.rb +6 -0
- data/smoke/hello/hello.rb +2 -2
- data/smoke/interface/a.rb +14 -0
- data/smoke/interface/a.rbi +12 -0
- data/smoke/module/a.rb +1 -1
- data/smoke/module/a.rbi +3 -3
- data/smoke/module/b.rb +1 -1
- data/smoke/stdout/a.rb +2 -2
- data/stdlib/builtin.rbi +6 -7
- data/steep.gemspec +1 -1
- metadata +14 -7
- data/lib/steep/module_name.rb +0 -116
- data/lib/steep/type_name.rb +0 -93
data/lib/steep/module_name.rb
DELETED
@@ -1,116 +0,0 @@
|
|
1
|
-
module Steep
|
2
|
-
class ModuleName
|
3
|
-
attr_reader :name
|
4
|
-
|
5
|
-
def initialize(name:, absolute:)
|
6
|
-
@name = name
|
7
|
-
@absolute = absolute
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.parse(name)
|
11
|
-
name = name.to_s
|
12
|
-
new(name: name.gsub(/\A::/, ""), absolute: name.start_with?("::"))
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.from_node(node)
|
16
|
-
case node.type
|
17
|
-
when :const
|
18
|
-
relative_node = new(name: node.children.last.to_s, absolute: false)
|
19
|
-
parent_node = node.children.first
|
20
|
-
|
21
|
-
case parent_node&.type
|
22
|
-
when :cbase
|
23
|
-
relative_node.absolute!
|
24
|
-
when nil
|
25
|
-
relative_node
|
26
|
-
else
|
27
|
-
from_node(parent_node)&.yield_self do |parent|
|
28
|
-
parent + relative_node
|
29
|
-
end
|
30
|
-
end
|
31
|
-
when :casgn
|
32
|
-
relative_node = new(name: node.children[1].to_s, absolute: false)
|
33
|
-
parent_node = node.children.first
|
34
|
-
|
35
|
-
case parent_node&.type
|
36
|
-
when :cbase
|
37
|
-
relative_node.absolute!
|
38
|
-
when nil
|
39
|
-
relative_node
|
40
|
-
else
|
41
|
-
from_node(parent_node)&.yield_self do |parent|
|
42
|
-
parent + relative_node
|
43
|
-
end
|
44
|
-
end
|
45
|
-
else
|
46
|
-
nil
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def ==(other)
|
51
|
-
other.is_a?(self.class) && other.name == name && other.absolute? == absolute?
|
52
|
-
end
|
53
|
-
|
54
|
-
def hash
|
55
|
-
self.class.hash ^ name.hash ^ @absolute.hash
|
56
|
-
end
|
57
|
-
|
58
|
-
alias eql? ==
|
59
|
-
|
60
|
-
def absolute!
|
61
|
-
self.class.new(name: name, absolute: true)
|
62
|
-
end
|
63
|
-
|
64
|
-
def absolute?
|
65
|
-
!!@absolute
|
66
|
-
end
|
67
|
-
|
68
|
-
def relative?
|
69
|
-
!absolute?
|
70
|
-
end
|
71
|
-
|
72
|
-
def to_s
|
73
|
-
if absolute?
|
74
|
-
"::#{name}"
|
75
|
-
else
|
76
|
-
name
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def +(other)
|
81
|
-
case other
|
82
|
-
when self.class
|
83
|
-
if other.absolute?
|
84
|
-
other
|
85
|
-
else
|
86
|
-
self.class.new(name: "#{name}::#{other.name}", absolute: absolute?)
|
87
|
-
end
|
88
|
-
else
|
89
|
-
self + self.class.parse(other)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def components
|
94
|
-
name.split(/::/).map.with_index {|s, index|
|
95
|
-
if index == 0 && absolute?
|
96
|
-
self.class.parse(s).absolute!
|
97
|
-
else
|
98
|
-
self.class.parse(s)
|
99
|
-
end
|
100
|
-
}
|
101
|
-
end
|
102
|
-
|
103
|
-
def parent
|
104
|
-
components = components()
|
105
|
-
components.pop
|
106
|
-
|
107
|
-
unless components.empty?
|
108
|
-
self.class.parse(components.join("::"))
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def simple?
|
113
|
-
components.size == 1
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
data/lib/steep/type_name.rb
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
module Steep
|
2
|
-
module TypeName
|
3
|
-
class Base
|
4
|
-
attr_reader :name
|
5
|
-
|
6
|
-
def initialize(name:)
|
7
|
-
@name = name
|
8
|
-
end
|
9
|
-
|
10
|
-
def ==(other)
|
11
|
-
other.is_a?(self.class) && other.name == name
|
12
|
-
end
|
13
|
-
|
14
|
-
def hash
|
15
|
-
self.class.hash ^ name.hash
|
16
|
-
end
|
17
|
-
|
18
|
-
alias eql? ==
|
19
|
-
|
20
|
-
def to_s
|
21
|
-
name.to_s
|
22
|
-
end
|
23
|
-
|
24
|
-
def map_module_name
|
25
|
-
self.class.new(name: yield(name))
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
class Interface < Base
|
30
|
-
def map_module_name
|
31
|
-
self
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
class Class < Base
|
36
|
-
attr_reader :constructor
|
37
|
-
|
38
|
-
def to_s
|
39
|
-
k = case constructor
|
40
|
-
when nil
|
41
|
-
""
|
42
|
-
when true
|
43
|
-
" constructor"
|
44
|
-
when false
|
45
|
-
" noconstructor"
|
46
|
-
end
|
47
|
-
|
48
|
-
"#{name}.class#{k}"
|
49
|
-
end
|
50
|
-
|
51
|
-
def initialize(name:, constructor:)
|
52
|
-
super(name: name)
|
53
|
-
@constructor = constructor
|
54
|
-
end
|
55
|
-
|
56
|
-
def ==(other)
|
57
|
-
other.is_a?(self.class) && other.name == name && other.constructor == constructor
|
58
|
-
end
|
59
|
-
|
60
|
-
def hash
|
61
|
-
self.class.hash ^ name.hash ^ constructor.hash
|
62
|
-
end
|
63
|
-
|
64
|
-
NOTHING = Object.new
|
65
|
-
|
66
|
-
def updated(constructor: NOTHING)
|
67
|
-
if NOTHING == constructor
|
68
|
-
constructor = self.constructor
|
69
|
-
end
|
70
|
-
|
71
|
-
self.class.new(name: name, constructor: constructor)
|
72
|
-
end
|
73
|
-
|
74
|
-
def map_module_name
|
75
|
-
self.class.new(name: yield(name), constructor: constructor)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
class Module < Base
|
80
|
-
def to_s
|
81
|
-
"#{name}.module"
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
class Instance < Base; end
|
86
|
-
|
87
|
-
class Alias < Base
|
88
|
-
def map_module_name
|
89
|
-
self
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|