steep 0.11.1 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (299) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +27 -0
  3. data/.gitmodules +3 -0
  4. data/CHANGELOG.md +5 -0
  5. data/README.md +48 -90
  6. data/Rakefile +10 -6
  7. data/Steepfile +1 -0
  8. data/bin/setup +1 -0
  9. data/bin/smoke_runner.rb +9 -14
  10. data/exe/rbs +3 -0
  11. data/exe/ruby-signature +3 -0
  12. data/exe/steep +1 -0
  13. data/lib/steep.rb +32 -26
  14. data/lib/steep/annotation_parser.rb +167 -0
  15. data/lib/steep/ast/annotation/collection.rb +7 -7
  16. data/lib/steep/ast/types.rb +60 -0
  17. data/lib/steep/ast/types/any.rb +1 -1
  18. data/lib/steep/ast/types/factory.rb +535 -0
  19. data/lib/steep/ast/types/name.rb +3 -3
  20. data/lib/steep/ast/types/var.rb +1 -1
  21. data/lib/steep/cli.rb +56 -240
  22. data/lib/steep/drivers/annotations.rb +36 -19
  23. data/lib/steep/drivers/check.rb +55 -91
  24. data/lib/steep/drivers/init.rb +54 -0
  25. data/lib/steep/drivers/langserver.rb +241 -150
  26. data/lib/steep/drivers/print_project.rb +56 -0
  27. data/lib/steep/drivers/signature_error_printer.rb +25 -0
  28. data/lib/steep/drivers/trace_printer.rb +25 -0
  29. data/lib/steep/drivers/utils/driver_helper.rb +26 -0
  30. data/lib/steep/drivers/validate.rb +18 -38
  31. data/lib/steep/drivers/vendor.rb +46 -0
  32. data/lib/steep/drivers/watch.rb +78 -140
  33. data/lib/steep/errors.rb +22 -13
  34. data/lib/steep/interface/interface.rb +91 -0
  35. data/lib/steep/interface/method.rb +0 -4
  36. data/lib/steep/interface/method_type.rb +362 -2
  37. data/lib/steep/interface/substitution.rb +22 -0
  38. data/lib/steep/project.rb +25 -233
  39. data/lib/steep/project/dsl.rb +132 -0
  40. data/lib/steep/project/file.rb +93 -76
  41. data/lib/steep/project/file_loader.rb +63 -0
  42. data/lib/steep/project/options.rb +7 -0
  43. data/lib/steep/project/target.rb +190 -0
  44. data/lib/steep/signature/errors.rb +25 -77
  45. data/lib/steep/signature/validator.rb +122 -0
  46. data/lib/steep/source.rb +12 -7
  47. data/lib/steep/subtyping/check.rb +357 -633
  48. data/lib/steep/subtyping/constraints.rb +2 -2
  49. data/lib/steep/subtyping/trace.rb +23 -0
  50. data/lib/steep/type_construction.rb +509 -455
  51. data/lib/steep/type_inference/constant_env.rb +16 -24
  52. data/lib/steep/type_inference/type_env.rb +26 -18
  53. data/lib/steep/version.rb +1 -1
  54. data/sample/Steepfile +6 -0
  55. data/sample/lib/conference.rb +12 -0
  56. data/sample/sig/conference.rbs +6 -0
  57. data/smoke/alias/Steepfile +4 -0
  58. data/smoke/alias/a.rb +2 -2
  59. data/smoke/alias/{a.rbi → a.rbs} +1 -1
  60. data/smoke/and/Steepfile +4 -0
  61. data/smoke/array/Steepfile +4 -0
  62. data/smoke/array/a.rb +2 -2
  63. data/smoke/array/b.rb +4 -4
  64. data/smoke/array/c.rb +2 -2
  65. data/smoke/block/Steepfile +5 -0
  66. data/smoke/block/{a.rbi → a.rbs} +1 -1
  67. data/smoke/block/{c.rbi → c.rbs} +0 -0
  68. data/smoke/block/d.rb +6 -6
  69. data/smoke/case/Steepfile +4 -0
  70. data/smoke/case/a.rb +4 -3
  71. data/smoke/class/Steepfile +4 -0
  72. data/smoke/class/a.rb +1 -4
  73. data/smoke/class/a.rbs +24 -0
  74. data/smoke/class/h.rb +6 -2
  75. data/smoke/class/{h.rbi → h.rbs} +1 -2
  76. data/smoke/class/i.rb +1 -2
  77. data/smoke/class/i.rbs +9 -0
  78. data/smoke/const/Steepfile +4 -0
  79. data/smoke/dstr/Steepfile +4 -0
  80. data/smoke/ensure/Steepfile +4 -0
  81. data/smoke/ensure/a.rb +1 -1
  82. data/smoke/enumerator/Steepfile +4 -0
  83. data/smoke/enumerator/a.rb +7 -7
  84. data/smoke/enumerator/b.rb +6 -6
  85. data/smoke/extension/Steepfile +4 -0
  86. data/smoke/extension/{a.rbi → a.rbs} +2 -2
  87. data/smoke/extension/{e.rbi → e.rbs} +2 -2
  88. data/smoke/hash/Steepfile +4 -0
  89. data/smoke/hash/{a.rbi → a.rbs} +0 -0
  90. data/smoke/hash/b.rb +2 -2
  91. data/smoke/hash/c.rb +1 -1
  92. data/smoke/hash/e.rbs +3 -0
  93. data/smoke/hash/f.rb +1 -1
  94. data/smoke/hello/Steepfile +4 -0
  95. data/smoke/hello/hello.rbs +7 -0
  96. data/smoke/if/Steepfile +4 -0
  97. data/smoke/implements/Steepfile +4 -0
  98. data/smoke/implements/a.rbs +6 -0
  99. data/smoke/initialize/Steepfile +4 -0
  100. data/smoke/initialize/a.rbs +3 -0
  101. data/smoke/integer/Steepfile +4 -0
  102. data/smoke/integer/a.rb +5 -3
  103. data/smoke/interface/Steepfile +4 -0
  104. data/smoke/interface/{a.rbi → a.rbs} +0 -0
  105. data/smoke/kwbegin/Steepfile +4 -0
  106. data/smoke/lambda/Steepfile +4 -0
  107. data/smoke/lambda/a.rb +9 -2
  108. data/smoke/literal/Steepfile +4 -0
  109. data/smoke/literal/{literal_methods.rbi → literal_methods.rbs} +0 -0
  110. data/smoke/map/Steepfile +4 -0
  111. data/smoke/map/a.rb +1 -1
  112. data/smoke/method/Steepfile +4 -0
  113. data/smoke/method/{a.rbi → a.rbs} +0 -0
  114. data/smoke/method/b.rb +1 -4
  115. data/smoke/method/d.rb +1 -0
  116. data/smoke/method/d.rbs +3 -0
  117. data/smoke/module/Steepfile +4 -0
  118. data/smoke/module/a.rb +1 -1
  119. data/smoke/module/a.rbs +16 -0
  120. data/smoke/module/c.rb +1 -1
  121. data/smoke/regexp/Steepfile +4 -0
  122. data/smoke/regexp/a.rb +2 -2
  123. data/smoke/regexp/b.rb +16 -16
  124. data/smoke/regression/Steepfile +5 -0
  125. data/smoke/regression/array.rb +2 -2
  126. data/smoke/regression/hash.rb +2 -2
  127. data/smoke/regression/poly_new.rb +2 -0
  128. data/smoke/regression/poly_new.rbs +4 -0
  129. data/smoke/regression/set_divide.rb +2 -2
  130. data/smoke/rescue/Steepfile +4 -0
  131. data/smoke/rescue/a.rb +1 -1
  132. data/smoke/self/Steepfile +4 -0
  133. data/smoke/self/a.rbs +4 -0
  134. data/smoke/skip/Steepfile +4 -0
  135. data/smoke/stdout/Steepfile +4 -0
  136. data/smoke/stdout/{a.rbi → a.rbs} +1 -1
  137. data/smoke/super/Steepfile +4 -0
  138. data/smoke/super/a.rbs +10 -0
  139. data/smoke/type_case/Steepfile +4 -0
  140. data/smoke/type_case/a.rb +1 -1
  141. data/smoke/yield/Steepfile +4 -0
  142. data/smoke/yield/a.rb +2 -2
  143. data/steep.gemspec +14 -7
  144. data/vendor/ruby-signature/.github/workflows/ruby.yml +27 -0
  145. data/vendor/ruby-signature/.gitignore +12 -0
  146. data/vendor/ruby-signature/.rubocop.yml +15 -0
  147. data/vendor/ruby-signature/BSDL +22 -0
  148. data/vendor/ruby-signature/COPYING +56 -0
  149. data/vendor/ruby-signature/Gemfile +6 -0
  150. data/vendor/ruby-signature/README.md +93 -0
  151. data/vendor/ruby-signature/Rakefile +66 -0
  152. data/vendor/ruby-signature/bin/annotate-with-rdoc +156 -0
  153. data/vendor/ruby-signature/bin/console +14 -0
  154. data/vendor/ruby-signature/bin/query-rdoc +103 -0
  155. data/vendor/ruby-signature/bin/setup +10 -0
  156. data/vendor/ruby-signature/bin/sort +88 -0
  157. data/vendor/ruby-signature/bin/test_runner.rb +17 -0
  158. data/vendor/ruby-signature/docs/CONTRIBUTING.md +97 -0
  159. data/vendor/ruby-signature/docs/sigs.md +148 -0
  160. data/vendor/ruby-signature/docs/stdlib.md +152 -0
  161. data/vendor/ruby-signature/docs/syntax.md +528 -0
  162. data/vendor/ruby-signature/exe/rbs +3 -0
  163. data/vendor/ruby-signature/exe/ruby-signature +7 -0
  164. data/vendor/ruby-signature/lib/ruby/signature.rb +64 -0
  165. data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +29 -0
  166. data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +29 -0
  167. data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +391 -0
  168. data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +364 -0
  169. data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +52 -0
  170. data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +54 -0
  171. data/vendor/ruby-signature/lib/ruby/signature/cli.rb +534 -0
  172. data/vendor/ruby-signature/lib/ruby/signature/constant.rb +28 -0
  173. data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +152 -0
  174. data/vendor/ruby-signature/lib/ruby/signature/definition.rb +172 -0
  175. data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +921 -0
  176. data/vendor/ruby-signature/lib/ruby/signature/environment.rb +283 -0
  177. data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +138 -0
  178. data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +126 -0
  179. data/vendor/ruby-signature/lib/ruby/signature/errors.rb +189 -0
  180. data/vendor/ruby-signature/lib/ruby/signature/location.rb +104 -0
  181. data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +125 -0
  182. data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +93 -0
  183. data/vendor/ruby-signature/lib/ruby/signature/parser.y +1343 -0
  184. data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +441 -0
  185. data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +579 -0
  186. data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +383 -0
  187. data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +48 -0
  188. data/vendor/ruby-signature/lib/ruby/signature/test.rb +28 -0
  189. data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +63 -0
  190. data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +290 -0
  191. data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +58 -0
  192. data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +324 -0
  193. data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +185 -0
  194. data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +256 -0
  195. data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +72 -0
  196. data/vendor/ruby-signature/lib/ruby/signature/types.rb +932 -0
  197. data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +140 -0
  198. data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +49 -0
  199. data/vendor/ruby-signature/lib/ruby/signature/version.rb +5 -0
  200. data/vendor/ruby-signature/lib/ruby/signature/writer.rb +271 -0
  201. data/vendor/ruby-signature/ruby-signature.gemspec +45 -0
  202. data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +3 -0
  203. data/vendor/ruby-signature/stdlib/base64/base64.rbs +15 -0
  204. data/vendor/ruby-signature/stdlib/builtin/array.rbs +1997 -0
  205. data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +280 -0
  206. data/vendor/ruby-signature/stdlib/builtin/binding.rbs +177 -0
  207. data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +35 -0
  208. data/vendor/ruby-signature/stdlib/builtin/class.rbs +145 -0
  209. data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +116 -0
  210. data/vendor/ruby-signature/stdlib/builtin/complex.rbs +400 -0
  211. data/vendor/ruby-signature/stdlib/builtin/constants.rbs +37 -0
  212. data/vendor/ruby-signature/stdlib/builtin/data.rbs +5 -0
  213. data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +2 -0
  214. data/vendor/ruby-signature/stdlib/builtin/dir.rbs +419 -0
  215. data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +606 -0
  216. data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +404 -0
  217. data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +260 -0
  218. data/vendor/ruby-signature/stdlib/builtin/errno.rbs +781 -0
  219. data/vendor/ruby-signature/stdlib/builtin/errors.rbs +582 -0
  220. data/vendor/ruby-signature/stdlib/builtin/exception.rbs +193 -0
  221. data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +40 -0
  222. data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +68 -0
  223. data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +12 -0
  224. data/vendor/ruby-signature/stdlib/builtin/file.rbs +476 -0
  225. data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +59 -0
  226. data/vendor/ruby-signature/stdlib/builtin/float.rbs +696 -0
  227. data/vendor/ruby-signature/stdlib/builtin/gc.rbs +121 -0
  228. data/vendor/ruby-signature/stdlib/builtin/hash.rbs +1029 -0
  229. data/vendor/ruby-signature/stdlib/builtin/integer.rbs +710 -0
  230. data/vendor/ruby-signature/stdlib/builtin/io.rbs +683 -0
  231. data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +574 -0
  232. data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +135 -0
  233. data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +141 -0
  234. data/vendor/ruby-signature/stdlib/builtin/math.rbs +66 -0
  235. data/vendor/ruby-signature/stdlib/builtin/method.rbs +182 -0
  236. data/vendor/ruby-signature/stdlib/builtin/module.rbs +248 -0
  237. data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +82 -0
  238. data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +409 -0
  239. data/vendor/ruby-signature/stdlib/builtin/object.rbs +824 -0
  240. data/vendor/ruby-signature/stdlib/builtin/proc.rbs +426 -0
  241. data/vendor/ruby-signature/stdlib/builtin/process.rbs +354 -0
  242. data/vendor/ruby-signature/stdlib/builtin/random.rbs +93 -0
  243. data/vendor/ruby-signature/stdlib/builtin/range.rbs +226 -0
  244. data/vendor/ruby-signature/stdlib/builtin/rational.rbs +424 -0
  245. data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +10 -0
  246. data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +131 -0
  247. data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +14 -0
  248. data/vendor/ruby-signature/stdlib/builtin/signal.rbs +55 -0
  249. data/vendor/ruby-signature/stdlib/builtin/string.rbs +770 -0
  250. data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +13 -0
  251. data/vendor/ruby-signature/stdlib/builtin/struct.rbs +40 -0
  252. data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +230 -0
  253. data/vendor/ruby-signature/stdlib/builtin/thread.rbs +1112 -0
  254. data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +23 -0
  255. data/vendor/ruby-signature/stdlib/builtin/time.rbs +739 -0
  256. data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +91 -0
  257. data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +46 -0
  258. data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +159 -0
  259. data/vendor/ruby-signature/stdlib/builtin/warning.rbs +17 -0
  260. data/vendor/ruby-signature/stdlib/erb/erb.rbs +18 -0
  261. data/vendor/ruby-signature/stdlib/find/find.rbs +44 -0
  262. data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +21 -0
  263. data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +23 -0
  264. data/vendor/ruby-signature/stdlib/prime/prime.rbs +188 -0
  265. data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +9 -0
  266. data/vendor/ruby-signature/stdlib/set/set.rbs +77 -0
  267. data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +53 -0
  268. metadata +244 -54
  269. data/.travis.yml +0 -7
  270. data/lib/steep/ast/signature/alias.rb +0 -19
  271. data/lib/steep/ast/signature/class.rb +0 -33
  272. data/lib/steep/ast/signature/const.rb +0 -17
  273. data/lib/steep/ast/signature/env.rb +0 -138
  274. data/lib/steep/ast/signature/extension.rb +0 -21
  275. data/lib/steep/ast/signature/gvar.rb +0 -17
  276. data/lib/steep/ast/signature/interface.rb +0 -31
  277. data/lib/steep/ast/signature/members.rb +0 -115
  278. data/lib/steep/ast/signature/module.rb +0 -21
  279. data/lib/steep/drivers/print_interface.rb +0 -94
  280. data/lib/steep/drivers/scaffold.rb +0 -321
  281. data/lib/steep/drivers/utils/each_signature.rb +0 -31
  282. data/lib/steep/interface/abstract.rb +0 -68
  283. data/lib/steep/interface/builder.rb +0 -637
  284. data/lib/steep/interface/instantiated.rb +0 -163
  285. data/lib/steep/interface/ivar_chain.rb +0 -26
  286. data/lib/steep/parser.y +0 -1278
  287. data/lib/steep/project/listener.rb +0 -53
  288. data/smoke/class/a.rbi +0 -24
  289. data/smoke/class/d.rb +0 -9
  290. data/smoke/class/e.rb +0 -12
  291. data/smoke/class/i.rbi +0 -9
  292. data/smoke/hash/e.rbi +0 -3
  293. data/smoke/hello/hello.rbi +0 -7
  294. data/smoke/implements/a.rbi +0 -6
  295. data/smoke/initialize/a.rbi +0 -3
  296. data/smoke/module/a.rbi +0 -16
  297. data/smoke/self/a.rbi +0 -4
  298. data/smoke/super/a.rbi +0 -10
  299. data/stdlib/builtin.rbi +0 -787
@@ -1,20 +1,18 @@
1
1
  module Steep
2
2
  module TypeInference
3
3
  class ConstantEnv
4
- attr_reader :builder
5
4
  attr_reader :context
6
5
  attr_reader :cache
6
+ attr_reader :factory
7
+ attr_reader :table
7
8
 
8
- # ConstantEnv receives an optional Names::Module, not a Namespace, because this is a simulation of Ruby.
9
+ # ConstantEnv receives an Names::Module as a context, not a Namespace, because this is a simulation of Ruby.
9
10
  # Any namespace is a module or class.
10
- def initialize(builder:, context:)
11
+ def initialize(factory:, context:)
11
12
  @cache = {}
12
- @builder = builder
13
+ @factory = factory
13
14
  @context = context
14
- end
15
-
16
- def signatures
17
- builder.signatures
15
+ @table = Ruby::Signature::ConstantTable.new(builder: factory.definition_builder)
18
16
  end
19
17
 
20
18
  def namespace
@@ -26,24 +24,18 @@ module Steep
26
24
  end
27
25
 
28
26
  def lookup(name)
29
- cache[name] ||= lookup0(name, namespace: namespace)
30
- end
27
+ cache[name] ||= begin
28
+ constant = table.resolve_constant_reference(
29
+ factory.type_name_1(name),
30
+ context: factory.namespace_1(namespace)
31
+ )
31
32
 
32
- # @type method lookup0: (Names::Module, namespace: AST::Namespace) -> Type
33
- def lookup0(name, namespace:)
34
- full_name = name.in_namespace(namespace)
35
- case
36
- when signatures.module_name?(full_name)
37
- AST::Types::Name::Module.new(name: full_name)
38
- when signatures.class_name?(full_name)
39
- AST::Types::Name::Class.new(name: full_name, constructor: true)
40
- when signatures.const_name?(full_name)
41
- builder.absolute_type(signatures.find_const(name, current_module: namespace).type,
42
- current: namespace)
43
- else
44
- unless namespace.empty?
45
- lookup0(name, namespace: namespace.parent)
33
+ if constant
34
+ factory.type(constant.type)
46
35
  end
36
+ rescue => exn
37
+ Steep.logger.error "Looking up a constant failed: name=#{name}, context=#{context}, error=#{exn.inspect}"
38
+ nil
47
39
  end
48
40
  end
49
41
  end
@@ -37,23 +37,27 @@ module Steep
37
37
  annotations.const_types.each do |name, type|
38
38
  env.set(const: name, type: type)
39
39
  end
40
- signatures.globals.each do |name, annot|
41
- type = subtyping.builder.absolute_type(annot.type, current: AST::Namespace.root)
42
- env.set(gvar: name, type: type)
40
+ signatures.name_to_global.each do |name, global|
41
+ type = signatures.absolute_type(global.type, namespace: Ruby::Signature::Namespace.root) {|ty| ty.name.absolute! }
42
+ env.set(gvar: name, type: subtyping.factory.type(type))
43
43
  end
44
44
  end
45
45
  end
46
46
 
47
- def with_annotations(lvar_types: {}, ivar_types: {}, const_types: {}, gvar_types: {}, &block)
47
+ def with_annotations(lvar_types: {}, ivar_types: {}, const_types: {}, gvar_types: {}, self_type:, &block)
48
48
  dup.tap do |env|
49
- merge!(original_env: env.lvar_types, override_env: lvar_types, &block)
50
- merge!(original_env: env.ivar_types, override_env: ivar_types, &block)
51
- merge!(original_env: env.gvar_types, override_env: gvar_types, &block)
49
+ merge!(original_env: env.lvar_types, override_env: lvar_types, self_type: self_type, &block)
50
+ merge!(original_env: env.ivar_types, override_env: ivar_types, self_type: self_type, &block)
51
+ merge!(original_env: env.gvar_types, override_env: gvar_types, self_type: self_type, &block)
52
52
 
53
53
  const_types.each do |name, annotated_type|
54
54
  original_type = self.const_types[name] || const_env.lookup(name)
55
55
  if original_type
56
- assert_annotation name, original_type: original_type, annotated_type: annotated_type, &block
56
+ assert_annotation name,
57
+ original_type: original_type,
58
+ annotated_type: annotated_type,
59
+ self_type: self_type,
60
+ &block
57
61
  end
58
62
  env.const_types[name] = annotated_type
59
63
  end
@@ -142,14 +146,14 @@ module Steep
142
146
  # | (gvar: Symbol, type: AST::Type) { (Subtyping::Result::Failure | nil) -> void } -> AST::Type
143
147
  # | (ivar: Symbol, type: AST::Type) { (Subtyping::Result::Failure | nil) -> void } -> AST::Type
144
148
  # | (lvar: Symbol | LabeledName, type: AST::Type) { (Subtyping::Result::Failure) -> void } -> AST::Type
145
- def assign(lvar: nil, const: nil, gvar: nil, ivar: nil, type:, &block)
149
+ def assign(lvar: nil, const: nil, gvar: nil, ivar: nil, type:, self_type:, &block)
146
150
  case
147
151
  when lvar
148
152
  yield_self do
149
153
  name = lvar_name(lvar)
150
154
  var_type = lvar_types[name]
151
155
  if var_type
152
- assert_assign(var_type: var_type, lhs_type: type, &block)
156
+ assert_assign(var_type: var_type, lhs_type: type, self_type: self_type, &block)
153
157
  else
154
158
  lvar_types[name] = type
155
159
  end
@@ -158,7 +162,7 @@ module Steep
158
162
  yield_self do
159
163
  const_type = const_types[const] || const_env.lookup(const)
160
164
  if const_type
161
- assert_assign(var_type: const_type, lhs_type: type, &block)
165
+ assert_assign(var_type: const_type, lhs_type: type, self_type: self_type, &block)
162
166
  else
163
167
  yield nil
164
168
  AST::Types::Any.new
@@ -167,7 +171,7 @@ module Steep
167
171
  else
168
172
  lookup_dictionary(ivar: ivar, gvar: gvar) do |var_name, dictionary|
169
173
  if dictionary.key?(var_name)
170
- assert_assign(var_type: dictionary[var_name], lhs_type: type, &block)
174
+ assert_assign(var_type: dictionary[var_name], lhs_type: type, self_type: self_type, &block)
171
175
  else
172
176
  yield nil
173
177
  AST::Types::Any.new
@@ -194,34 +198,38 @@ module Steep
194
198
  end
195
199
  end
196
200
 
197
- def assert_assign(var_type:, lhs_type:)
201
+ def assert_assign(var_type:, lhs_type:, self_type:)
202
+ return var_type if var_type == lhs_type
203
+
198
204
  var_type = subtyping.expand_alias(var_type)
199
205
  lhs_type = subtyping.expand_alias(lhs_type)
200
206
 
201
207
  relation = Subtyping::Relation.new(sub_type: lhs_type, super_type: var_type)
202
208
  constraints = Subtyping::Constraints.new(unknowns: Set.new)
203
209
 
204
- subtyping.check(relation, constraints: constraints).else do |result|
210
+ subtyping.check(relation, self_type: self_type, constraints: constraints).else do |result|
205
211
  yield result
206
212
  end
207
213
 
208
214
  var_type
209
215
  end
210
216
 
211
- def merge!(original_env:, override_env:, &block)
217
+ def merge!(original_env:, override_env:, self_type:, &block)
212
218
  original_env.merge!(override_env) do |name, original_type, override_type|
213
- assert_annotation name, annotated_type: override_type, original_type: original_type, &block
219
+ assert_annotation name, annotated_type: override_type, original_type: original_type, self_type: self_type, &block
214
220
  end
215
221
  end
216
222
 
217
- def assert_annotation(name, annotated_type:, original_type:)
223
+ def assert_annotation(name, annotated_type:, original_type:, self_type:)
224
+ return annotated_type if annotated_type == original_type
225
+
218
226
  annotated_type = subtyping.expand_alias(annotated_type)
219
227
  original_type = subtyping.expand_alias(original_type)
220
228
 
221
229
  relation = Subtyping::Relation.new(sub_type: annotated_type, super_type: original_type)
222
230
  constraints = Subtyping::Constraints.new(unknowns: Set.new)
223
231
 
224
- subtyping.check(relation, constraints: constraints).else do |result|
232
+ subtyping.check(relation, constraints: constraints, self_type: self_type).else do |result|
225
233
  yield name, relation, result
226
234
  end
227
235
 
data/lib/steep/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Steep
2
- VERSION = "0.11.1"
2
+ VERSION = "0.12.0"
3
3
  end
data/sample/Steepfile ADDED
@@ -0,0 +1,6 @@
1
+ target :app do
2
+ check "lib"
3
+ signature "sig"
4
+
5
+ library "set", "pathname"
6
+ end
@@ -0,0 +1,12 @@
1
+ class Conference
2
+ # @dynamic title, year
3
+ attr_reader :title
4
+ attr_reader :year
5
+
6
+ def initialize(title:, year:)
7
+ @title = title
8
+ @year = year
9
+ end
10
+ end
11
+
12
+ Conference.new()
@@ -0,0 +1,6 @@
1
+ class Conference
2
+ attr_reader title: String
3
+ attr_reader year: Integer
4
+
5
+ def initialize: (title: String, year: Integer) -> void
6
+ end
@@ -0,0 +1,4 @@
1
+ target :test do
2
+ check "*.rb"
3
+ signature "*.rbs"
4
+ end
data/smoke/alias/a.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  # @type var x: foo
2
2
  x = ""
3
3
 
4
- # !expects NoMethodError: type=::foo, method=+
4
+ # !expects ArgumentTypeMismatch: receiver=(::Integer | ::String), expected=::String, actual=::Integer
5
5
  x + 123
6
6
 
7
- # @type var y: bar<Integer>
7
+ # @type var y: bar
8
8
  y = x
9
9
  y = []
10
10
 
@@ -1,5 +1,5 @@
1
1
  type foo = String | Integer
2
- type bar<'a> = Array<'a> | foo
2
+ type bar = Array[Integer] | foo
3
3
  type baz = [String, Symbol]
4
4
 
5
5
  type name = :foo | :bar
@@ -0,0 +1,4 @@
1
+ target :test do
2
+ check "*.rb"
3
+ signature "*.rbs"
4
+ end
@@ -0,0 +1,4 @@
1
+ target :test do
2
+ check "*.rb"
3
+ signature "*.rbs"
4
+ end
data/smoke/array/a.rb CHANGED
@@ -1,9 +1,9 @@
1
- # @type var a: Array<Integer>
1
+ # @type var a: Array[Integer]
2
2
 
3
3
  a = []
4
4
  a[1] = 3
5
5
 
6
- # !expects ArgumentTypeMismatch: receiver=::Array<::Integer>, expected=::Integer, actual=::String
6
+ # !expects* UnresolvedOverloading: receiver=::Array[::Integer], method_name=[]=,
7
7
  a[2] = "foo"
8
8
 
9
9
  # @type var i: Integer
data/smoke/array/b.rb CHANGED
@@ -6,11 +6,11 @@ x = y
6
6
  # !expects IncompatibleAssignment: lhs_type=::Integer, rhs_type=::String
7
7
  y = x
8
8
 
9
- # @type var a: Array<Integer>
10
- # @type var b: Array<String>
9
+ # @type var a: Array[Integer]
10
+ # @type var b: Array[String]
11
11
 
12
12
  a = []
13
- # !expects IncompatibleAssignment: lhs_type=::Array<::String>, rhs_type=::Array<::Integer>
13
+ # !expects IncompatibleAssignment: lhs_type=::Array[::String], rhs_type=::Array[::Integer]
14
14
  b = a
15
- # !expects IncompatibleAssignment: lhs_type=::Array<::Integer>, rhs_type=::Array<::String>
15
+ # !expects IncompatibleAssignment: lhs_type=::Array[::Integer], rhs_type=::Array[::String]
16
16
  a = b
data/smoke/array/c.rb CHANGED
@@ -1,7 +1,7 @@
1
- # @type var x: Array<String?>
1
+ # @type var x: Array[String?]
2
2
 
3
3
  x = ["foo"]
4
4
  x = [nil]
5
5
 
6
- # !expects IncompatibleAssignment: lhs_type=::Array<(::String | nil)>, rhs_type=::Array<::Integer>
6
+ # !expects IncompatibleAssignment: lhs_type=::Array[(::String | nil)], rhs_type=::Array[::Integer]
7
7
  x = [1]
@@ -0,0 +1,5 @@
1
+ target :test do
2
+ check "*.rb"
3
+ signature "*.rbs"
4
+ end
5
+
@@ -1,5 +1,5 @@
1
1
  class A
2
- def foo: { (String) -> any } -> String
2
+ def foo: { (String) -> untyped } -> String
3
3
  | -> Integer
4
4
 
5
5
  def bar: { (String) -> Integer } -> Symbol
File without changes
data/smoke/block/d.rb CHANGED
@@ -1,15 +1,15 @@
1
1
  # @type var a: ^(Integer) -> String
2
2
  a = -> (x) { x.to_s }
3
3
 
4
- # @type var b: Array<Float>
4
+ # @type var b: Array[Float]
5
5
 
6
- # !expects IncompatibleAssignment: lhs_type=::Array<::Float>, rhs_type=::Array<::String>
6
+ # !expects IncompatibleAssignment: lhs_type=::Array[::Float], rhs_type=::Array[::String]
7
7
  b = [1,2,3].map(&a)
8
8
 
9
- # !expects IncompatibleAssignment: lhs_type=::Array<::Float>, rhs_type=::Array<::String>
9
+ # !expects IncompatibleAssignment: lhs_type=::Array[::Float], rhs_type=::Array[::String]
10
10
  b = [1,2,3].map(&:to_s)
11
11
 
12
- # !expects* BlockTypeMismatch:
12
+ # !expects* UnresolvedOverloading: receiver=::Array[::Integer], method_name=map,
13
13
  [1,2,3].map(&:no_such_method)
14
- # !expects* BlockTypeMismatch:
15
- [1,2,3].map(&:floor)
14
+ # !expects* UnresolvedOverloading: receiver=::Array[::Integer], method_name=map,
15
+ [1,2,3].map(&:divmod)
@@ -0,0 +1,4 @@
1
+ target :test do
2
+ check "*.rb"
3
+ signature "*.rbs"
4
+ end
data/smoke/case/a.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # @type var a: Integer
2
2
 
3
- # !expects IncompatibleAssignment: lhs_type=::Integer, rhs_type=(::Array<::String> | ::Integer | ::String | nil)
3
+ # !expects IncompatibleAssignment: lhs_type=::Integer, rhs_type=(::Array[::String] | ::Integer | ::String | nil)
4
4
  a = case 1
5
5
  when 2
6
6
  1
@@ -13,8 +13,9 @@ a = case 1
13
13
  "string"
14
14
  end
15
15
 
16
+ # !expects IncompatibleAssignment: lhs_type=::Integer, rhs_type=(::Integer | nil)
16
17
  a = case
17
- # !expects ArgumentTypeMismatch: receiver=::Integer, expected=::Integer, actual=::String
18
+ # !expects* UnresolvedOverloading: receiver=::Integer, method_name=+,
18
19
  when 1+"a"
19
- (_ = nil)
20
+ 30
20
21
  end
@@ -0,0 +1,4 @@
1
+ target :test do
2
+ check "*.rb"
3
+ signature "*.rbs"
4
+ end
data/smoke/class/a.rb CHANGED
@@ -1,10 +1,7 @@
1
1
  class A
2
- # @type instance: A
3
- # @type module: A.class
4
-
5
2
  # A#foo is defined and the implementation is compatible.
6
3
  def foo(x)
7
- x
4
+ x + ""
8
5
  end
9
6
 
10
7
  # A#bar is defined but the implementation is incompatible.
data/smoke/class/a.rbs ADDED
@@ -0,0 +1,24 @@
1
+ class A
2
+ def foo: (String) -> untyped
3
+ def bar: () -> String
4
+ def self.baz: -> Integer
5
+ end
6
+
7
+ class B
8
+ def name: -> String
9
+ end
10
+
11
+ class C
12
+ def foo: -> instance
13
+ def bar: -> instance
14
+ end
15
+
16
+ class D
17
+ def initialize: (String) -> untyped
18
+ def foo: -> untyped
19
+ end
20
+
21
+ class E
22
+ def initialize: () -> untyped
23
+ def foo: -> untyped
24
+ end
data/smoke/class/h.rb CHANGED
@@ -7,9 +7,13 @@ class WithSingletonConstructor
7
7
  end
8
8
 
9
9
  def self.create()
10
- new(foo: "hoge")
10
+ instance = new(foo: "hoge")
11
+
12
+ instance.foo
13
+
14
+ _ = instance
11
15
  end
12
16
 
13
17
  new(foo: "hoge")
14
- create()
18
+ create().foo
15
19
  end
@@ -1,7 +1,6 @@
1
1
  class WithSingletonConstructor
2
2
  attr_reader foo: String
3
3
 
4
- def initialize: (foo: String) -> any
4
+ def initialize: (foo: String) -> void
5
5
  def self.create: -> instance
6
6
  end
7
-
data/smoke/class/i.rb CHANGED
@@ -8,10 +8,9 @@ class IncompatibleChild
8
8
  end
9
9
 
10
10
  def initialize()
11
- # !expects IncompatibleArguments: receiver=::IncompatibleChild, method_type=(name: ::String) -> any
11
+ # !expects IncompatibleArguments: receiver=::IncompatibleChild, method_type=(name: ::String) -> untyped
12
12
  super()
13
13
 
14
- # !expects IncompatibleZuper: method=initialize
15
14
  super
16
15
  end
17
16
  end