steep 0.13.0 → 0.16.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +0 -3
  3. data/CHANGELOG.md +28 -0
  4. data/Rakefile +0 -13
  5. data/bin/setup +0 -2
  6. data/bin/smoke_runner.rb +0 -1
  7. data/exe/steep +0 -1
  8. data/lib/steep.rb +33 -1
  9. data/lib/steep/annotation_parser.rb +4 -4
  10. data/lib/steep/ast/buffer.rb +11 -7
  11. data/lib/steep/ast/builtin.rb +8 -0
  12. data/lib/steep/ast/types/factory.rb +124 -89
  13. data/lib/steep/cli.rb +16 -1
  14. data/lib/steep/drivers/annotations.rb +1 -1
  15. data/lib/steep/drivers/check.rb +20 -4
  16. data/lib/steep/drivers/init.rb +5 -5
  17. data/lib/steep/drivers/langserver.rb +13 -287
  18. data/lib/steep/drivers/utils/driver_helper.rb +1 -1
  19. data/lib/steep/drivers/vendor.rb +2 -2
  20. data/lib/steep/drivers/watch.rb +97 -85
  21. data/lib/steep/drivers/worker.rb +51 -0
  22. data/lib/steep/project.rb +9 -5
  23. data/lib/steep/project/completion_provider.rb +298 -0
  24. data/lib/steep/project/dsl.rb +14 -0
  25. data/lib/steep/project/file.rb +54 -47
  26. data/lib/steep/project/hover_content.rb +17 -8
  27. data/lib/steep/project/options.rb +25 -3
  28. data/lib/steep/project/target.rb +40 -24
  29. data/lib/steep/server/base_worker.rb +56 -0
  30. data/lib/steep/server/code_worker.rb +151 -0
  31. data/lib/steep/server/interaction_worker.rb +281 -0
  32. data/lib/steep/server/master.rb +196 -0
  33. data/lib/steep/server/signature_worker.rb +148 -0
  34. data/lib/steep/server/utils.rb +36 -0
  35. data/lib/steep/server/worker_process.rb +62 -0
  36. data/lib/steep/signature/errors.rb +1 -1
  37. data/lib/steep/signature/validator.rb +13 -13
  38. data/lib/steep/source.rb +1 -1
  39. data/lib/steep/type_construction.rb +1004 -727
  40. data/lib/steep/type_inference/constant_env.rb +3 -11
  41. data/lib/steep/type_inference/context.rb +8 -3
  42. data/lib/steep/type_inference/context_array.rb +111 -0
  43. data/lib/steep/type_inference/local_variable_type_env.rb +226 -0
  44. data/lib/steep/type_inference/logic.rb +130 -0
  45. data/lib/steep/type_inference/type_env.rb +5 -69
  46. data/lib/steep/typing.rb +91 -23
  47. data/lib/steep/version.rb +1 -1
  48. data/smoke/alias/Steepfile +1 -0
  49. data/smoke/alias/a.rb +1 -1
  50. data/smoke/and/Steepfile +1 -0
  51. data/smoke/array/Steepfile +1 -0
  52. data/smoke/array/b.rb +0 -2
  53. data/smoke/block/Steepfile +1 -0
  54. data/smoke/case/Steepfile +1 -0
  55. data/smoke/class/Steepfile +1 -0
  56. data/smoke/const/Steepfile +1 -0
  57. data/smoke/dstr/Steepfile +1 -0
  58. data/smoke/ensure/Steepfile +1 -0
  59. data/smoke/enumerator/Steepfile +1 -0
  60. data/smoke/extension/Steepfile +1 -0
  61. data/smoke/extension/c.rb +1 -0
  62. data/smoke/hash/Steepfile +1 -0
  63. data/smoke/hello/Steepfile +1 -0
  64. data/smoke/if/Steepfile +1 -0
  65. data/smoke/if/a.rb +1 -1
  66. data/smoke/implements/Steepfile +1 -0
  67. data/smoke/initialize/Steepfile +1 -0
  68. data/smoke/integer/Steepfile +1 -0
  69. data/smoke/interface/Steepfile +1 -0
  70. data/smoke/kwbegin/Steepfile +1 -0
  71. data/smoke/lambda/Steepfile +1 -0
  72. data/smoke/literal/Steepfile +1 -0
  73. data/smoke/map/Steepfile +1 -0
  74. data/smoke/method/Steepfile +1 -0
  75. data/smoke/module/Steepfile +1 -0
  76. data/smoke/regexp/Steepfile +1 -0
  77. data/smoke/regexp/b.rb +4 -4
  78. data/smoke/regression/Steepfile +1 -0
  79. data/smoke/rescue/Steepfile +1 -0
  80. data/smoke/rescue/a.rb +1 -1
  81. data/smoke/self/Steepfile +1 -0
  82. data/smoke/skip/Steepfile +1 -0
  83. data/smoke/stdout/Steepfile +1 -0
  84. data/smoke/super/Steepfile +1 -0
  85. data/smoke/type_case/Steepfile +1 -0
  86. data/smoke/yield/Steepfile +1 -0
  87. data/steep.gemspec +8 -8
  88. metadata +38 -138
  89. data/exe/rbs +0 -3
  90. data/exe/ruby-signature +0 -3
  91. data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
  92. data/vendor/ruby-signature/.gitignore +0 -12
  93. data/vendor/ruby-signature/.rubocop.yml +0 -15
  94. data/vendor/ruby-signature/BSDL +0 -22
  95. data/vendor/ruby-signature/COPYING +0 -56
  96. data/vendor/ruby-signature/Gemfile +0 -6
  97. data/vendor/ruby-signature/README.md +0 -93
  98. data/vendor/ruby-signature/Rakefile +0 -66
  99. data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -156
  100. data/vendor/ruby-signature/bin/console +0 -14
  101. data/vendor/ruby-signature/bin/query-rdoc +0 -103
  102. data/vendor/ruby-signature/bin/setup +0 -10
  103. data/vendor/ruby-signature/bin/sort +0 -88
  104. data/vendor/ruby-signature/bin/test_runner.rb +0 -17
  105. data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
  106. data/vendor/ruby-signature/docs/sigs.md +0 -148
  107. data/vendor/ruby-signature/docs/stdlib.md +0 -152
  108. data/vendor/ruby-signature/docs/syntax.md +0 -528
  109. data/vendor/ruby-signature/exe/rbs +0 -3
  110. data/vendor/ruby-signature/exe/ruby-signature +0 -7
  111. data/vendor/ruby-signature/lib/ruby/signature.rb +0 -64
  112. data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +0 -29
  113. data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +0 -29
  114. data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +0 -391
  115. data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +0 -364
  116. data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +0 -52
  117. data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +0 -54
  118. data/vendor/ruby-signature/lib/ruby/signature/cli.rb +0 -534
  119. data/vendor/ruby-signature/lib/ruby/signature/constant.rb +0 -28
  120. data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +0 -152
  121. data/vendor/ruby-signature/lib/ruby/signature/definition.rb +0 -172
  122. data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +0 -921
  123. data/vendor/ruby-signature/lib/ruby/signature/environment.rb +0 -283
  124. data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +0 -138
  125. data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +0 -126
  126. data/vendor/ruby-signature/lib/ruby/signature/errors.rb +0 -189
  127. data/vendor/ruby-signature/lib/ruby/signature/location.rb +0 -104
  128. data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +0 -125
  129. data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +0 -93
  130. data/vendor/ruby-signature/lib/ruby/signature/parser.y +0 -1343
  131. data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +0 -441
  132. data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +0 -579
  133. data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +0 -383
  134. data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +0 -48
  135. data/vendor/ruby-signature/lib/ruby/signature/test.rb +0 -28
  136. data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +0 -63
  137. data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +0 -290
  138. data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +0 -58
  139. data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +0 -324
  140. data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +0 -185
  141. data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +0 -256
  142. data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +0 -72
  143. data/vendor/ruby-signature/lib/ruby/signature/types.rb +0 -932
  144. data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +0 -140
  145. data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +0 -49
  146. data/vendor/ruby-signature/lib/ruby/signature/version.rb +0 -5
  147. data/vendor/ruby-signature/lib/ruby/signature/writer.rb +0 -271
  148. data/vendor/ruby-signature/ruby-signature.gemspec +0 -45
  149. data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -3
  150. data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -15
  151. data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
  152. data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
  153. data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
  154. data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -35
  155. data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
  156. data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
  157. data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
  158. data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
  159. data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
  160. data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
  161. data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -419
  162. data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -606
  163. data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
  164. data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
  165. data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
  166. data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
  167. data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -193
  168. data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
  169. data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
  170. data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
  171. data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -476
  172. data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
  173. data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
  174. data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -121
  175. data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
  176. data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -710
  177. data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
  178. data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -574
  179. data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -135
  180. data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -141
  181. data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -66
  182. data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -182
  183. data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -248
  184. data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
  185. data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
  186. data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
  187. data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -426
  188. data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -354
  189. data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -93
  190. data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
  191. data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
  192. data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -10
  193. data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -131
  194. data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
  195. data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
  196. data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -770
  197. data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -13
  198. data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
  199. data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -230
  200. data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1112
  201. data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
  202. data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -739
  203. data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -91
  204. data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
  205. data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -159
  206. data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
  207. data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -18
  208. data/vendor/ruby-signature/stdlib/find/find.rbs +0 -44
  209. data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -21
  210. data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
  211. data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
  212. data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
  213. data/vendor/ruby-signature/stdlib/set/set.rbs +0 -77
  214. 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: Ruby::Signature::Namespace.root) {|ty| ty.name.absolute! }
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(lvar_types: {}, ivar_types: {}, const_types: {}, gvar_types: {}, self_type:, &block)
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
- # | (lvar: Symbol) { () -> AST::Type | nil } -> AST::Type
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(lvar: nil, const: nil, gvar: nil, ivar: nil, type:)
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
- # | (lvar: Symbol | LabeledName, type: AST::Type) { (Subtyping::Result::Failure) -> void } -> AST::Type
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
 
@@ -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
- @contexts = {}.compare_by_identity
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, context)
42
+ def add_typing(node, type, _context)
27
43
  typing[node] = type
28
- contexts[node] = context
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 "Unknown node for typing: #{node.inspect}"
67
+ raise UnknownNodeError.new(:type, node: node)
52
68
  end
53
69
  end
54
70
  end
55
71
 
56
- def context_of(node:)
57
- ctx = contexts[node]
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
- if parent
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(parent: self)
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, contexts[node])
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
@@ -1,3 +1,3 @@
1
1
  module Steep
2
- VERSION = "0.13.0"
2
+ VERSION = "0.16.2"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  target :test do
2
+ typing_options :strict
2
3
  check "*.rb"
3
4
  signature "*.rbs"
4
5
  end
@@ -1,7 +1,7 @@
1
1
  # @type var x: foo
2
2
  x = ""
3
3
 
4
- # !expects ArgumentTypeMismatch: receiver=(::Integer | ::String), expected=::String, actual=::Integer
4
+ # !expects ArgumentTypeMismatch: receiver=(::Integer | ::String), expected=::string, actual=::Integer
5
5
  x + 123
6
6
 
7
7
  # @type var y: bar
@@ -1,4 +1,5 @@
1
1
  target :test do
2
+ typing_options :strict
2
3
  check "*.rb"
3
4
  signature "*.rbs"
4
5
  end
@@ -1,4 +1,5 @@
1
1
  target :test do
2
+ typing_options :strict
2
3
  check "*.rb"
3
4
  signature "*.rbs"
4
5
  end
@@ -1,9 +1,7 @@
1
1
  x = ""
2
2
  y = 1
3
3
 
4
- # !expects IncompatibleAssignment: lhs_type=::String, rhs_type=::Integer
5
4
  x = y
6
- # !expects IncompatibleAssignment: lhs_type=::Integer, rhs_type=::String
7
5
  y = x
8
6
 
9
7
  # @type var a: Array[Integer]
@@ -1,4 +1,5 @@
1
1
  target :test do
2
+ typing_options :strict
2
3
  check "*.rb"
3
4
  signature "*.rbs"
4
5
  end
@@ -1,4 +1,5 @@
1
1
  target :test do
2
+ typing_options :strict
2
3
  check "*.rb"
3
4
  signature "*.rbs"
4
5
  end
@@ -1,4 +1,5 @@
1
1
  target :test do
2
+ typing_options :strict
2
3
  check "*.rb"
3
4
  signature "*.rbs"
4
5
  end
@@ -1,4 +1,5 @@
1
1
  target :test do
2
+ typing_options :strict
2
3
  check "*.rb"
3
4
  signature "*.rbs"
4
5
  end
@@ -1,4 +1,5 @@
1
1
  target :test do
2
+ typing_options :strict
2
3
  check "*.rb"
3
4
  signature "*.rbs"
4
5
  end
@@ -1,4 +1,5 @@
1
1
  target :test do
2
+ typing_options :strict
2
3
  check "*.rb"
3
4
  signature "*.rbs"
4
5
  end
@@ -1,4 +1,5 @@
1
1
  target :test do
2
+ typing_options :strict
2
3
  check "*.rb"
3
4
  signature "*.rbs"
4
5
  end
@@ -1,4 +1,5 @@
1
1
  target :test do
2
+ typing_options :strict
2
3
  check "*.rb"
3
4
  signature "*.rbs"
4
5
  end
@@ -5,5 +5,6 @@ class Foo
5
5
  # @type var string: String
6
6
  # !expects IncompatibleAssignment: lhs_type=::String, rhs_type=::Object
7
7
  string = super()
8
+ string
8
9
  end
9
10
  end
@@ -1,4 +1,5 @@
1
1
  target :test do
2
+ typing_options :strict
2
3
  check "*.rb"
3
4
  signature "*.rbs"
4
5
  end
@@ -1,4 +1,5 @@
1
1
  target :test do
2
+ typing_options :strict
2
3
  check "*.rb"
3
4
  signature "*.rbs"
4
5
  end
@@ -1,4 +1,5 @@
1
1
  target :test do
2
+ typing_options :strict
2
3
  check "*.rb"
3
4
  signature "*.rbs"
4
5
  end