steep 0.13.0 → 0.16.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +0 -3
- data/CHANGELOG.md +28 -0
- data/Rakefile +0 -13
- data/bin/setup +0 -2
- data/bin/smoke_runner.rb +0 -1
- data/exe/steep +0 -1
- data/lib/steep.rb +33 -1
- data/lib/steep/annotation_parser.rb +4 -4
- data/lib/steep/ast/buffer.rb +11 -7
- data/lib/steep/ast/builtin.rb +8 -0
- data/lib/steep/ast/types/factory.rb +124 -89
- data/lib/steep/cli.rb +16 -1
- data/lib/steep/drivers/annotations.rb +1 -1
- data/lib/steep/drivers/check.rb +20 -4
- data/lib/steep/drivers/init.rb +5 -5
- data/lib/steep/drivers/langserver.rb +13 -287
- data/lib/steep/drivers/utils/driver_helper.rb +1 -1
- data/lib/steep/drivers/vendor.rb +2 -2
- data/lib/steep/drivers/watch.rb +97 -85
- data/lib/steep/drivers/worker.rb +51 -0
- data/lib/steep/project.rb +9 -5
- data/lib/steep/project/completion_provider.rb +298 -0
- data/lib/steep/project/dsl.rb +14 -0
- data/lib/steep/project/file.rb +54 -47
- data/lib/steep/project/hover_content.rb +17 -8
- data/lib/steep/project/options.rb +25 -3
- data/lib/steep/project/target.rb +40 -24
- data/lib/steep/server/base_worker.rb +56 -0
- data/lib/steep/server/code_worker.rb +151 -0
- data/lib/steep/server/interaction_worker.rb +281 -0
- data/lib/steep/server/master.rb +196 -0
- data/lib/steep/server/signature_worker.rb +148 -0
- data/lib/steep/server/utils.rb +36 -0
- data/lib/steep/server/worker_process.rb +62 -0
- data/lib/steep/signature/errors.rb +1 -1
- data/lib/steep/signature/validator.rb +13 -13
- data/lib/steep/source.rb +1 -1
- data/lib/steep/type_construction.rb +1004 -727
- data/lib/steep/type_inference/constant_env.rb +3 -11
- data/lib/steep/type_inference/context.rb +8 -3
- data/lib/steep/type_inference/context_array.rb +111 -0
- data/lib/steep/type_inference/local_variable_type_env.rb +226 -0
- data/lib/steep/type_inference/logic.rb +130 -0
- data/lib/steep/type_inference/type_env.rb +5 -69
- data/lib/steep/typing.rb +91 -23
- data/lib/steep/version.rb +1 -1
- data/smoke/alias/Steepfile +1 -0
- data/smoke/alias/a.rb +1 -1
- data/smoke/and/Steepfile +1 -0
- data/smoke/array/Steepfile +1 -0
- data/smoke/array/b.rb +0 -2
- data/smoke/block/Steepfile +1 -0
- data/smoke/case/Steepfile +1 -0
- data/smoke/class/Steepfile +1 -0
- data/smoke/const/Steepfile +1 -0
- data/smoke/dstr/Steepfile +1 -0
- data/smoke/ensure/Steepfile +1 -0
- data/smoke/enumerator/Steepfile +1 -0
- data/smoke/extension/Steepfile +1 -0
- data/smoke/extension/c.rb +1 -0
- data/smoke/hash/Steepfile +1 -0
- data/smoke/hello/Steepfile +1 -0
- data/smoke/if/Steepfile +1 -0
- data/smoke/if/a.rb +1 -1
- data/smoke/implements/Steepfile +1 -0
- data/smoke/initialize/Steepfile +1 -0
- data/smoke/integer/Steepfile +1 -0
- data/smoke/interface/Steepfile +1 -0
- data/smoke/kwbegin/Steepfile +1 -0
- data/smoke/lambda/Steepfile +1 -0
- data/smoke/literal/Steepfile +1 -0
- data/smoke/map/Steepfile +1 -0
- data/smoke/method/Steepfile +1 -0
- data/smoke/module/Steepfile +1 -0
- data/smoke/regexp/Steepfile +1 -0
- data/smoke/regexp/b.rb +4 -4
- data/smoke/regression/Steepfile +1 -0
- data/smoke/rescue/Steepfile +1 -0
- data/smoke/rescue/a.rb +1 -1
- data/smoke/self/Steepfile +1 -0
- data/smoke/skip/Steepfile +1 -0
- data/smoke/stdout/Steepfile +1 -0
- data/smoke/super/Steepfile +1 -0
- data/smoke/type_case/Steepfile +1 -0
- data/smoke/yield/Steepfile +1 -0
- data/steep.gemspec +8 -8
- metadata +38 -138
- data/exe/rbs +0 -3
- data/exe/ruby-signature +0 -3
- data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
- data/vendor/ruby-signature/.gitignore +0 -12
- data/vendor/ruby-signature/.rubocop.yml +0 -15
- data/vendor/ruby-signature/BSDL +0 -22
- data/vendor/ruby-signature/COPYING +0 -56
- data/vendor/ruby-signature/Gemfile +0 -6
- data/vendor/ruby-signature/README.md +0 -93
- data/vendor/ruby-signature/Rakefile +0 -66
- data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -156
- data/vendor/ruby-signature/bin/console +0 -14
- data/vendor/ruby-signature/bin/query-rdoc +0 -103
- data/vendor/ruby-signature/bin/setup +0 -10
- data/vendor/ruby-signature/bin/sort +0 -88
- data/vendor/ruby-signature/bin/test_runner.rb +0 -17
- data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
- data/vendor/ruby-signature/docs/sigs.md +0 -148
- data/vendor/ruby-signature/docs/stdlib.md +0 -152
- data/vendor/ruby-signature/docs/syntax.md +0 -528
- data/vendor/ruby-signature/exe/rbs +0 -3
- data/vendor/ruby-signature/exe/ruby-signature +0 -7
- data/vendor/ruby-signature/lib/ruby/signature.rb +0 -64
- data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +0 -29
- data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +0 -29
- data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +0 -391
- data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +0 -364
- data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +0 -52
- data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +0 -54
- data/vendor/ruby-signature/lib/ruby/signature/cli.rb +0 -534
- data/vendor/ruby-signature/lib/ruby/signature/constant.rb +0 -28
- data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +0 -152
- data/vendor/ruby-signature/lib/ruby/signature/definition.rb +0 -172
- data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +0 -921
- data/vendor/ruby-signature/lib/ruby/signature/environment.rb +0 -283
- data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +0 -138
- data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +0 -126
- data/vendor/ruby-signature/lib/ruby/signature/errors.rb +0 -189
- data/vendor/ruby-signature/lib/ruby/signature/location.rb +0 -104
- data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +0 -125
- data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +0 -93
- data/vendor/ruby-signature/lib/ruby/signature/parser.y +0 -1343
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +0 -441
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +0 -579
- data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +0 -383
- data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +0 -48
- data/vendor/ruby-signature/lib/ruby/signature/test.rb +0 -28
- data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +0 -63
- data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +0 -290
- data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +0 -58
- data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +0 -324
- data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +0 -185
- data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +0 -256
- data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +0 -72
- data/vendor/ruby-signature/lib/ruby/signature/types.rb +0 -932
- data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +0 -140
- data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +0 -49
- data/vendor/ruby-signature/lib/ruby/signature/version.rb +0 -5
- data/vendor/ruby-signature/lib/ruby/signature/writer.rb +0 -271
- data/vendor/ruby-signature/ruby-signature.gemspec +0 -45
- data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -3
- data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -15
- data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
- data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
- data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
- data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -35
- data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
- data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
- data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
- data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
- data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
- data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
- data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -419
- data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -606
- data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
- data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
- data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
- data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
- data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -193
- data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
- data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
- data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
- data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -476
- data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
- data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
- data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -121
- data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
- data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -710
- data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
- data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -574
- data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -135
- data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -141
- data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -66
- data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -182
- data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -248
- data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
- data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
- data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
- data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -426
- data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -354
- data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -93
- data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
- data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
- data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -10
- data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -131
- data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
- data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
- data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -770
- data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -13
- data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
- data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -230
- data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1112
- data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
- data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -739
- data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -91
- data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
- data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -159
- data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
- data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -18
- data/vendor/ruby-signature/stdlib/find/find.rbs +0 -44
- data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -21
- data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
- data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
- data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
- data/vendor/ruby-signature/stdlib/set/set.rbs +0 -77
- data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
@@ -2,7 +2,6 @@ module Steep
|
|
2
2
|
module TypeInference
|
3
3
|
class TypeEnv
|
4
4
|
attr_reader :subtyping
|
5
|
-
attr_reader :lvar_types
|
6
5
|
attr_reader :const_types
|
7
6
|
attr_reader :gvar_types
|
8
7
|
attr_reader :ivar_types
|
@@ -10,7 +9,6 @@ module Steep
|
|
10
9
|
|
11
10
|
def initialize(subtyping:, const_env:)
|
12
11
|
@subtyping = subtyping
|
13
|
-
@lvar_types = {}
|
14
12
|
@const_types = {}
|
15
13
|
@gvar_types = {}
|
16
14
|
@ivar_types = {}
|
@@ -19,7 +17,6 @@ module Steep
|
|
19
17
|
|
20
18
|
def initialize_copy(other)
|
21
19
|
@subtyping = other.subtyping
|
22
|
-
@lvar_types = other.lvar_types.dup
|
23
20
|
@const_types = other.const_types.dup
|
24
21
|
@gvar_types = other.gvar_types.dup
|
25
22
|
@ivar_types = other.ivar_types.dup
|
@@ -28,9 +25,6 @@ module Steep
|
|
28
25
|
|
29
26
|
def self.build(annotations:, signatures:, subtyping:, const_env:)
|
30
27
|
new(subtyping: subtyping, const_env: const_env).tap do |env|
|
31
|
-
annotations.lvar_types.each do |name, type|
|
32
|
-
env.set(lvar: name, type: type)
|
33
|
-
end
|
34
28
|
annotations.ivar_types.each do |name, type|
|
35
29
|
env.set(ivar: name, type: type)
|
36
30
|
end
|
@@ -38,15 +32,14 @@ module Steep
|
|
38
32
|
env.set(const: name, type: type)
|
39
33
|
end
|
40
34
|
signatures.name_to_global.each do |name, global|
|
41
|
-
type = signatures.absolute_type(global.type, namespace:
|
35
|
+
type = signatures.absolute_type(global.type, namespace: RBS::Namespace.root) {|ty| ty.name.absolute! }
|
42
36
|
env.set(gvar: name, type: subtyping.factory.type(type))
|
43
37
|
end
|
44
38
|
end
|
45
39
|
end
|
46
40
|
|
47
|
-
def with_annotations(
|
41
|
+
def with_annotations(ivar_types: {}, const_types: {}, gvar_types: {}, self_type:, &block)
|
48
42
|
dup.tap do |env|
|
49
|
-
merge!(original_env: env.lvar_types, override_env: lvar_types, self_type: self_type, &block)
|
50
43
|
merge!(original_env: env.ivar_types, override_env: ivar_types, self_type: self_type, &block)
|
51
44
|
merge!(original_env: env.gvar_types, override_env: gvar_types, self_type: self_type, &block)
|
52
45
|
|
@@ -64,44 +57,11 @@ module Steep
|
|
64
57
|
end
|
65
58
|
end
|
66
59
|
|
67
|
-
def join!(envs)
|
68
|
-
lvars = {}
|
69
|
-
|
70
|
-
common_vars = envs.map {|env| Set.new(env.lvar_types.keys) }.inject {|a, b| a & b }
|
71
|
-
|
72
|
-
envs.each do |env|
|
73
|
-
env.lvar_types.each do |name, type|
|
74
|
-
unless lvar_types.key?(name)
|
75
|
-
lvars[name] = [] unless lvars[name]
|
76
|
-
lvars[name] << type
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
lvars.each do |name, types|
|
82
|
-
if lvar_types.key?(name) || common_vars.member?(name)
|
83
|
-
set(lvar: name, type: AST::Types::Union.build(types: types))
|
84
|
-
else
|
85
|
-
set(lvar: name, type: AST::Types::Union.build(types: types + [AST::Types::Nil.new]))
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
60
|
# @type method assert: (const: Names::Module) { () -> void } -> AST::Type
|
91
61
|
# | (gvar: Symbol) { () -> void } -> AST::Type
|
92
62
|
# | (ivar: Symbol) { () -> void } -> AST::Type
|
93
|
-
|
94
|
-
def get(lvar: nil, const: nil, gvar: nil, ivar: nil)
|
63
|
+
def get(const: nil, gvar: nil, ivar: nil)
|
95
64
|
case
|
96
|
-
when lvar
|
97
|
-
lvar_name(lvar).yield_self do |name|
|
98
|
-
if lvar_types.key?(name)
|
99
|
-
lvar_types[name]
|
100
|
-
else
|
101
|
-
ty = yield
|
102
|
-
lvar_types[name] = ty || AST::Types::Any.new
|
103
|
-
end
|
104
|
-
end
|
105
65
|
when const
|
106
66
|
if const_types.key?(const)
|
107
67
|
const_types[const]
|
@@ -127,12 +87,8 @@ module Steep
|
|
127
87
|
end
|
128
88
|
end
|
129
89
|
|
130
|
-
def set(
|
90
|
+
def set(const: nil, gvar: nil, ivar: nil, type:)
|
131
91
|
case
|
132
|
-
when lvar
|
133
|
-
lvar_name(lvar).yield_self do |name|
|
134
|
-
lvar_types[name] = type
|
135
|
-
end
|
136
92
|
when const
|
137
93
|
const_types[const] = type
|
138
94
|
else
|
@@ -145,19 +101,8 @@ module Steep
|
|
145
101
|
# @type method assign: (const: Names::Module, type: AST::Type) { (Subtyping::Result::Failure | nil) -> void } -> AST::Type
|
146
102
|
# | (gvar: Symbol, type: AST::Type) { (Subtyping::Result::Failure | nil) -> void } -> AST::Type
|
147
103
|
# | (ivar: Symbol, type: AST::Type) { (Subtyping::Result::Failure | nil) -> void } -> AST::Type
|
148
|
-
|
149
|
-
def assign(lvar: nil, const: nil, gvar: nil, ivar: nil, type:, self_type:, &block)
|
104
|
+
def assign(const: nil, gvar: nil, ivar: nil, type:, self_type:, &block)
|
150
105
|
case
|
151
|
-
when lvar
|
152
|
-
yield_self do
|
153
|
-
name = lvar_name(lvar)
|
154
|
-
var_type = lvar_types[name]
|
155
|
-
if var_type
|
156
|
-
assert_assign(var_type: var_type, lhs_type: type, self_type: self_type, &block)
|
157
|
-
else
|
158
|
-
lvar_types[name] = type
|
159
|
-
end
|
160
|
-
end
|
161
106
|
when const
|
162
107
|
yield_self do
|
163
108
|
const_type = const_types[const] || const_env.lookup(const)
|
@@ -189,15 +134,6 @@ module Steep
|
|
189
134
|
end
|
190
135
|
end
|
191
136
|
|
192
|
-
def lvar_name(lvar)
|
193
|
-
case lvar
|
194
|
-
when Symbol
|
195
|
-
lvar
|
196
|
-
when ASTUtils::Labeling::LabeledName
|
197
|
-
lvar.name
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
137
|
def assert_assign(var_type:, lhs_type:, self_type:)
|
202
138
|
return var_type if var_type == lhs_type
|
203
139
|
|
data/lib/steep/typing.rb
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
module Steep
|
2
2
|
class Typing
|
3
|
+
class UnknownNodeError < StandardError
|
4
|
+
attr_reader :op
|
5
|
+
attr_reader :node
|
6
|
+
|
7
|
+
def initialize(op, node:)
|
8
|
+
@op = op
|
9
|
+
@node = node
|
10
|
+
super "Unknown node for #{op}: #{node.inspect}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :source
|
3
15
|
attr_reader :errors
|
4
16
|
attr_reader :typing
|
5
17
|
attr_reader :parent
|
@@ -7,8 +19,11 @@ module Steep
|
|
7
19
|
attr_reader :last_update
|
8
20
|
attr_reader :should_update
|
9
21
|
attr_reader :contexts
|
22
|
+
attr_reader :root_context
|
23
|
+
|
24
|
+
def initialize(source:, root_context:, parent: nil, parent_last_update: parent&.last_update, contexts: nil)
|
25
|
+
@source = source
|
10
26
|
|
11
|
-
def initialize(parent: nil, parent_last_update: parent&.last_update)
|
12
27
|
@parent = parent
|
13
28
|
@parent_last_update = parent_last_update
|
14
29
|
@last_update = parent&.last_update || 0
|
@@ -16,25 +31,26 @@ module Steep
|
|
16
31
|
|
17
32
|
@errors = []
|
18
33
|
@typing = {}.compare_by_identity
|
19
|
-
@
|
34
|
+
@root_context = root_context
|
35
|
+
@contexts = contexts || TypeInference::ContextArray.from_source(source: source)
|
20
36
|
end
|
21
37
|
|
22
38
|
def add_error(error)
|
23
39
|
errors << error
|
24
40
|
end
|
25
41
|
|
26
|
-
def add_typing(node, type,
|
42
|
+
def add_typing(node, type, _context)
|
27
43
|
typing[node] = type
|
28
|
-
|
29
|
-
|
30
|
-
if should_update
|
31
|
-
@last_update += 1
|
32
|
-
@should_update = false
|
33
|
-
end
|
44
|
+
@last_update += 1
|
34
45
|
|
35
46
|
type
|
36
47
|
end
|
37
48
|
|
49
|
+
def add_context(range, context:)
|
50
|
+
contexts.insert_context(range, context: context)
|
51
|
+
@last_update += 1
|
52
|
+
end
|
53
|
+
|
38
54
|
def has_type?(node)
|
39
55
|
typing.key?(node)
|
40
56
|
end
|
@@ -48,25 +64,72 @@ module Steep
|
|
48
64
|
if parent
|
49
65
|
parent.type_of(node: node)
|
50
66
|
else
|
51
|
-
raise
|
67
|
+
raise UnknownNodeError.new(:type, node: node)
|
52
68
|
end
|
53
69
|
end
|
54
70
|
end
|
55
71
|
|
56
|
-
def
|
57
|
-
|
72
|
+
def add_context_for_node(node, context:)
|
73
|
+
begin_pos = node.loc.expression.begin_pos
|
74
|
+
end_pos = node.loc.expression.end_pos
|
75
|
+
|
76
|
+
add_context(begin_pos..end_pos, context: context)
|
77
|
+
end
|
78
|
+
|
79
|
+
def add_context_for_body(node, context:)
|
80
|
+
case node.type
|
81
|
+
when :class
|
82
|
+
name_node, super_node, _ = node.children
|
83
|
+
begin_pos = if super_node
|
84
|
+
super_node.loc.expression.end_pos
|
85
|
+
else
|
86
|
+
name_node.loc.expression.end_pos
|
87
|
+
end
|
88
|
+
end_pos = node.loc.end.begin_pos
|
89
|
+
|
90
|
+
add_context(begin_pos..end_pos, context: context)
|
91
|
+
|
92
|
+
when :module
|
93
|
+
name_node = node.children[0]
|
94
|
+
begin_pos = name_node.loc.expression.end_pos
|
95
|
+
end_pos = node.loc.end.begin_pos
|
96
|
+
add_context(begin_pos..end_pos, context: context)
|
97
|
+
|
98
|
+
when :def, :defs
|
99
|
+
args_node = case node.type
|
100
|
+
when :def
|
101
|
+
node.children[1]
|
102
|
+
when :defs
|
103
|
+
node.children[2]
|
104
|
+
end
|
105
|
+
body_begin_pos = if args_node.loc.expression
|
106
|
+
args_node.loc.expression.end_pos
|
107
|
+
else
|
108
|
+
node.loc.name.end_pos
|
109
|
+
end
|
110
|
+
body_end_pos = node.loc.end.begin_pos
|
111
|
+
add_context(body_begin_pos..body_end_pos, context: context)
|
112
|
+
|
113
|
+
when :block
|
114
|
+
send_node, args_node, _ = node.children
|
115
|
+
begin_pos = if send_node.type != :lambda && args_node.loc.expression
|
116
|
+
args_node.loc.expression.end_pos
|
117
|
+
else
|
118
|
+
node.loc.begin.end_pos
|
119
|
+
end
|
120
|
+
end_pos = node.loc.end.begin_pos
|
121
|
+
add_context(begin_pos..end_pos, context: context)
|
58
122
|
|
59
|
-
if ctx
|
60
|
-
ctx
|
61
123
|
else
|
62
|
-
|
63
|
-
parent.context_of(node: node)
|
64
|
-
else
|
65
|
-
raise "Unknown node for context: #{node.inspect}"
|
66
|
-
end
|
124
|
+
raise "Unexpected node for insert_context: #{node.type}"
|
67
125
|
end
|
68
126
|
end
|
69
127
|
|
128
|
+
def context_at(line:, column:)
|
129
|
+
contexts.at(line: line, column: column) ||
|
130
|
+
(parent ? parent.context_at(line: line, column: column) : root_context)
|
131
|
+
end
|
132
|
+
|
70
133
|
def dump(io)
|
71
134
|
io.puts "Typing: "
|
72
135
|
nodes.each_value do |node|
|
@@ -87,8 +150,11 @@ module Steep
|
|
87
150
|
"#{line}:#{col}:#{src}"
|
88
151
|
end
|
89
152
|
|
90
|
-
def new_child
|
91
|
-
child = self.class.new(
|
153
|
+
def new_child(range)
|
154
|
+
child = self.class.new(source: source,
|
155
|
+
parent: self,
|
156
|
+
root_context: root_context,
|
157
|
+
contexts: TypeInference::ContextArray.new(buffer: contexts.buffer, range: range, context: nil))
|
92
158
|
@should_update = true
|
93
159
|
|
94
160
|
if block_given?
|
@@ -104,12 +170,14 @@ module Steep
|
|
104
170
|
|
105
171
|
def save!
|
106
172
|
raise "Unexpected save!" unless parent
|
107
|
-
raise "Parent modified since new_child" unless parent.last_update == parent_last_update
|
173
|
+
raise "Parent modified since #new_child: parent.last_update=#{parent.last_update}, parent_last_update=#{parent_last_update}" unless parent.last_update == parent_last_update
|
108
174
|
|
109
175
|
each_typing do |node, type|
|
110
|
-
parent.add_typing(node, type,
|
176
|
+
parent.add_typing(node, type, nil)
|
111
177
|
end
|
112
178
|
|
179
|
+
parent.contexts.merge(contexts)
|
180
|
+
|
113
181
|
errors.each do |error|
|
114
182
|
parent.add_error error
|
115
183
|
end
|
data/lib/steep/version.rb
CHANGED
data/smoke/alias/Steepfile
CHANGED
data/smoke/alias/a.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# @type var x: foo
|
2
2
|
x = ""
|
3
3
|
|
4
|
-
# !expects ArgumentTypeMismatch: receiver=(::Integer | ::String), expected=::
|
4
|
+
# !expects ArgumentTypeMismatch: receiver=(::Integer | ::String), expected=::string, actual=::Integer
|
5
5
|
x + 123
|
6
6
|
|
7
7
|
# @type var y: bar
|
data/smoke/and/Steepfile
CHANGED
data/smoke/array/Steepfile
CHANGED
data/smoke/array/b.rb
CHANGED
data/smoke/block/Steepfile
CHANGED
data/smoke/case/Steepfile
CHANGED
data/smoke/class/Steepfile
CHANGED
data/smoke/const/Steepfile
CHANGED
data/smoke/dstr/Steepfile
CHANGED
data/smoke/ensure/Steepfile
CHANGED
data/smoke/enumerator/Steepfile
CHANGED
data/smoke/extension/Steepfile
CHANGED
data/smoke/extension/c.rb
CHANGED
data/smoke/hash/Steepfile
CHANGED
data/smoke/hello/Steepfile
CHANGED