steep 1.6.0 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (453) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/CHANGELOG.md +49 -0
  4. data/README.md +18 -0
  5. data/Rakefile +5 -0
  6. data/bin/output_test.rb +1 -0
  7. data/doc/narrowing.md +195 -0
  8. data/doc/shape.md +194 -0
  9. data/guides/src/gem-rbs-collection/gem-rbs-collection.md +7 -24
  10. data/guides/src/getting-started/getting-started.md +10 -11
  11. data/lib/steep/ast/ignore.rb +148 -0
  12. data/lib/steep/ast/types/factory.rb +27 -18
  13. data/lib/steep/ast/types/helper.rb +4 -0
  14. data/lib/steep/ast/types/intersection.rb +7 -0
  15. data/lib/steep/ast/types/proc.rb +14 -9
  16. data/lib/steep/ast/types/record.rb +7 -0
  17. data/lib/steep/ast/types/tuple.rb +7 -0
  18. data/lib/steep/ast/types/union.rb +7 -0
  19. data/lib/steep/cli.rb +6 -1
  20. data/lib/steep/diagnostic/ruby.rb +16 -0
  21. data/lib/steep/drivers/stats.rb +2 -2
  22. data/lib/steep/drivers/utils/driver_helper.rb +22 -11
  23. data/lib/steep/drivers/validate.rb +4 -2
  24. data/lib/steep/expectations.rb +2 -2
  25. data/lib/steep/interface/block.rb +1 -1
  26. data/lib/steep/interface/builder.rb +342 -358
  27. data/lib/steep/interface/function.rb +82 -11
  28. data/lib/steep/interface/method_type.rb +18 -10
  29. data/lib/steep/interface/shape.rb +69 -18
  30. data/lib/steep/interface/substitution.rb +4 -0
  31. data/lib/steep/node_helper.rb +30 -1
  32. data/lib/steep/project/dsl.rb +18 -21
  33. data/lib/steep/project/options.rb +39 -2
  34. data/lib/steep/project/pattern.rb +1 -2
  35. data/lib/steep/project.rb +11 -7
  36. data/lib/steep/rake_task.rb +132 -0
  37. data/lib/steep/server/change_buffer.rb +2 -2
  38. data/lib/steep/server/interaction_worker.rb +67 -11
  39. data/lib/steep/server/lsp_formatter.rb +2 -0
  40. data/lib/steep/server/worker_process.rb +3 -1
  41. data/lib/steep/services/completion_provider.rb +59 -26
  42. data/lib/steep/services/file_loader.rb +15 -19
  43. data/lib/steep/services/signature_help_provider.rb +37 -35
  44. data/lib/steep/services/type_check_service.rb +36 -8
  45. data/lib/steep/signature/validator.rb +185 -133
  46. data/lib/steep/source/ignore_ranges.rb +69 -0
  47. data/lib/steep/source.rb +10 -4
  48. data/lib/steep/subtyping/check.rb +50 -43
  49. data/lib/steep/subtyping/result.rb +6 -0
  50. data/lib/steep/subtyping/variable_variance.rb +3 -3
  51. data/lib/steep/test.rb +9 -0
  52. data/lib/steep/type_construction.rb +205 -309
  53. data/lib/steep/type_inference/block_params.rb +12 -4
  54. data/lib/steep/type_inference/case_when.rb +301 -0
  55. data/lib/steep/type_inference/context.rb +1 -1
  56. data/lib/steep/type_inference/logic_type_interpreter.rb +3 -2
  57. data/lib/steep/type_inference/method_params.rb +16 -0
  58. data/lib/steep/type_inference/send_args.rb +5 -2
  59. data/lib/steep/version.rb +1 -1
  60. data/lib/steep.rb +25 -8
  61. data/steep.gemspec +5 -2
  62. metadata +12 -396
  63. data/.github/dependabot.yml +0 -22
  64. data/.github/workflows/ruby-windows.yml +0 -34
  65. data/.github/workflows/ruby.yml +0 -33
  66. data/.vscode/steep-shared.code-snippets +0 -41
  67. data/Gemfile +0 -14
  68. data/Gemfile.lock +0 -104
  69. data/Gemfile.steep +0 -0
  70. data/gemfile_steep/Gemfile +0 -3
  71. data/gemfile_steep/Gemfile.lock +0 -64
  72. data/rbs_collection.steep.lock.yaml +0 -106
  73. data/rbs_collection.steep.yaml +0 -23
  74. data/sig/shims/bundler.rbs +0 -3
  75. data/sig/shims/concurrent-ruby.rbs +0 -39
  76. data/sig/shims/exception.rbs +0 -4
  77. data/sig/shims/language-server_protocol.rbs +0 -450
  78. data/sig/shims/parser/comment.rbs +0 -33
  79. data/sig/shims/parser/nodes.rbs +0 -252
  80. data/sig/shims/parser/source/map.rbs +0 -146
  81. data/sig/shims/parser/source/range.rbs +0 -237
  82. data/sig/shims/parser.rbs +0 -59
  83. data/sig/shims/string.rbs +0 -4
  84. data/sig/shims/tagged_logging.rbs +0 -6
  85. data/sig/steep/annotation_parser.rbs +0 -60
  86. data/sig/steep/ast/annotation/collection.rbs +0 -78
  87. data/sig/steep/ast/annotation.rbs +0 -121
  88. data/sig/steep/ast/builtin.rbs +0 -69
  89. data/sig/steep/ast/node/type_application.rbs +0 -31
  90. data/sig/steep/ast/node/type_assertion.rbs +0 -32
  91. data/sig/steep/ast/types/any.rbs +0 -29
  92. data/sig/steep/ast/types/boolean.rbs +0 -31
  93. data/sig/steep/ast/types/bot.rbs +0 -29
  94. data/sig/steep/ast/types/class.rbs +0 -33
  95. data/sig/steep/ast/types/factory.rbs +0 -110
  96. data/sig/steep/ast/types/helper.rbs +0 -22
  97. data/sig/steep/ast/types/instance.rbs +0 -33
  98. data/sig/steep/ast/types/intersection.rbs +0 -38
  99. data/sig/steep/ast/types/literal.rbs +0 -35
  100. data/sig/steep/ast/types/logic.rbs +0 -83
  101. data/sig/steep/ast/types/name.rbs +0 -80
  102. data/sig/steep/ast/types/nil.rbs +0 -31
  103. data/sig/steep/ast/types/proc.rbs +0 -53
  104. data/sig/steep/ast/types/record.rbs +0 -37
  105. data/sig/steep/ast/types/self.rbs +0 -33
  106. data/sig/steep/ast/types/top.rbs +0 -29
  107. data/sig/steep/ast/types/tuple.rbs +0 -35
  108. data/sig/steep/ast/types/union.rbs +0 -38
  109. data/sig/steep/ast/types/var.rbs +0 -42
  110. data/sig/steep/ast/types/void.rbs +0 -29
  111. data/sig/steep/ast/types.rbs +0 -16
  112. data/sig/steep/cli.rbs +0 -55
  113. data/sig/steep/diagnostic/deprecated/else_on_exhaustive_case.rbs +0 -13
  114. data/sig/steep/diagnostic/deprecated/unknown_constant_assigned.rbs +0 -15
  115. data/sig/steep/diagnostic/helper.rbs +0 -15
  116. data/sig/steep/diagnostic/lsp_formatter.rbs +0 -36
  117. data/sig/steep/diagnostic/ruby.rbs +0 -695
  118. data/sig/steep/diagnostic/signature.rbs +0 -252
  119. data/sig/steep/drivers/annotations.rbs +0 -17
  120. data/sig/steep/drivers/check.rbs +0 -33
  121. data/sig/steep/drivers/checkfile.rbs +0 -27
  122. data/sig/steep/drivers/diagnostic_printer.rbs +0 -25
  123. data/sig/steep/drivers/init.rbs +0 -19
  124. data/sig/steep/drivers/langserver.rbs +0 -36
  125. data/sig/steep/drivers/print_project.rbs +0 -15
  126. data/sig/steep/drivers/stats.rbs +0 -47
  127. data/sig/steep/drivers/utils/driver_helper.rbs +0 -25
  128. data/sig/steep/drivers/utils/jobs_option.rbs +0 -19
  129. data/sig/steep/drivers/validate.rbs +0 -15
  130. data/sig/steep/drivers/vendor.rbs +0 -19
  131. data/sig/steep/drivers/watch.rbs +0 -27
  132. data/sig/steep/drivers/worker.rbs +0 -29
  133. data/sig/steep/equatable.rbs +0 -11
  134. data/sig/steep/expectations.rbs +0 -72
  135. data/sig/steep/index/rbs_index.rbs +0 -141
  136. data/sig/steep/index/signature_symbol_provider.rbs +0 -41
  137. data/sig/steep/index/source_index.rbs +0 -63
  138. data/sig/steep/interface/block.rbs +0 -41
  139. data/sig/steep/interface/builder.rbs +0 -166
  140. data/sig/steep/interface/function.rbs +0 -265
  141. data/sig/steep/interface/method_type.rbs +0 -105
  142. data/sig/steep/interface/shape.rbs +0 -61
  143. data/sig/steep/interface/substitution.rbs +0 -49
  144. data/sig/steep/interface/type_param.rbs +0 -43
  145. data/sig/steep/method_name.rbs +0 -30
  146. data/sig/steep/module_helper.rbs +0 -16
  147. data/sig/steep/node_helper.rbs +0 -78
  148. data/sig/steep/path_helper.rbs +0 -15
  149. data/sig/steep/project/dsl.rbs +0 -104
  150. data/sig/steep/project/options.rbs +0 -27
  151. data/sig/steep/project/pattern.rbs +0 -47
  152. data/sig/steep/project/target.rbs +0 -25
  153. data/sig/steep/project.rbs +0 -26
  154. data/sig/steep/range_extension.rbs +0 -7
  155. data/sig/steep/server/base_worker.rbs +0 -49
  156. data/sig/steep/server/change_buffer.rbs +0 -36
  157. data/sig/steep/server/delay_queue.rbs +0 -37
  158. data/sig/steep/server/interaction_worker.rbs +0 -80
  159. data/sig/steep/server/lsp_formatter.rbs +0 -63
  160. data/sig/steep/server/master.rbs +0 -299
  161. data/sig/steep/server/type_check_worker.rbs +0 -141
  162. data/sig/steep/server/worker_process.rbs +0 -97
  163. data/sig/steep/services/completion_provider.rbs +0 -251
  164. data/sig/steep/services/content_change.rbs +0 -37
  165. data/sig/steep/services/file_loader.rbs +0 -21
  166. data/sig/steep/services/goto_service.rbs +0 -106
  167. data/sig/steep/services/hover_provider/rbs.rbs +0 -47
  168. data/sig/steep/services/hover_provider/ruby.rbs +0 -127
  169. data/sig/steep/services/hover_provider/singleton_methods.rbs +0 -11
  170. data/sig/steep/services/path_assignment.rbs +0 -21
  171. data/sig/steep/services/signature_help_provider.rbs +0 -49
  172. data/sig/steep/services/signature_service.rbs +0 -156
  173. data/sig/steep/services/stats_calculator.rbs +0 -41
  174. data/sig/steep/services/type_check_service.rbs +0 -107
  175. data/sig/steep/services/type_name_completion.rbs +0 -135
  176. data/sig/steep/signature/validator.rbs +0 -85
  177. data/sig/steep/source.rbs +0 -102
  178. data/sig/steep/subtyping/cache.rbs +0 -17
  179. data/sig/steep/subtyping/check.rbs +0 -129
  180. data/sig/steep/subtyping/constraints.rbs +0 -111
  181. data/sig/steep/subtyping/relation.rbs +0 -63
  182. data/sig/steep/subtyping/result.rbs +0 -175
  183. data/sig/steep/subtyping/variable_variance.rbs +0 -25
  184. data/sig/steep/thread_waiter.rbs +0 -13
  185. data/sig/steep/type_construction.rbs +0 -567
  186. data/sig/steep/type_inference/block_params.rbs +0 -170
  187. data/sig/steep/type_inference/constant_env.rbs +0 -29
  188. data/sig/steep/type_inference/context.rbs +0 -214
  189. data/sig/steep/type_inference/context_array.rbs +0 -38
  190. data/sig/steep/type_inference/logic_type_interpreter.rbs +0 -108
  191. data/sig/steep/type_inference/method_call.rbs +0 -124
  192. data/sig/steep/type_inference/method_params.rbs +0 -127
  193. data/sig/steep/type_inference/multiple_assignment.rbs +0 -76
  194. data/sig/steep/type_inference/send_args.rbs +0 -243
  195. data/sig/steep/type_inference/type_env.rbs +0 -160
  196. data/sig/steep/type_inference/type_env_builder.rbs +0 -81
  197. data/sig/steep/typing.rbs +0 -75
  198. data/sig/steep.rbs +0 -36
  199. data/smoke/alias/Steepfile +0 -6
  200. data/smoke/alias/a.rb +0 -16
  201. data/smoke/alias/a.rbs +0 -10
  202. data/smoke/alias/b.rb +0 -6
  203. data/smoke/alias/c.rb +0 -8
  204. data/smoke/alias/test_expectations.yml +0 -96
  205. data/smoke/and/Steepfile +0 -6
  206. data/smoke/and/a.rb +0 -8
  207. data/smoke/and/test_expectations.yml +0 -29
  208. data/smoke/array/Steepfile +0 -6
  209. data/smoke/array/a.rb +0 -18
  210. data/smoke/array/b.rb +0 -12
  211. data/smoke/array/c.rb +0 -6
  212. data/smoke/array/test_expectations.yml +0 -103
  213. data/smoke/block/Steepfile +0 -6
  214. data/smoke/block/a.rb +0 -10
  215. data/smoke/block/a.rbs +0 -6
  216. data/smoke/block/b.rb +0 -13
  217. data/smoke/block/c.rb +0 -9
  218. data/smoke/block/c.rbs +0 -3
  219. data/smoke/block/d.rb +0 -11
  220. data/smoke/block/e.rb +0 -12
  221. data/smoke/block/e.rbs +0 -4
  222. data/smoke/block/test_expectations.yml +0 -133
  223. data/smoke/case/Steepfile +0 -6
  224. data/smoke/case/a.rb +0 -18
  225. data/smoke/case/test_expectations.yml +0 -47
  226. data/smoke/class/Steepfile +0 -6
  227. data/smoke/class/a.rb +0 -25
  228. data/smoke/class/a.rbs +0 -23
  229. data/smoke/class/b.rb +0 -5
  230. data/smoke/class/c.rb +0 -9
  231. data/smoke/class/f.rb +0 -10
  232. data/smoke/class/g.rb +0 -6
  233. data/smoke/class/h.rb +0 -19
  234. data/smoke/class/h.rbs +0 -6
  235. data/smoke/class/i.rb +0 -14
  236. data/smoke/class/i.rbs +0 -9
  237. data/smoke/class/test_expectations.yml +0 -117
  238. data/smoke/compact/Steepfile +0 -6
  239. data/smoke/compact/a.rb +0 -2
  240. data/smoke/compact/a.rbs +0 -5
  241. data/smoke/compact/b.rb +0 -2
  242. data/smoke/compact/test_expectations.yml +0 -18
  243. data/smoke/const/Steepfile +0 -6
  244. data/smoke/const/a.rb +0 -27
  245. data/smoke/const/b.rb +0 -7
  246. data/smoke/const/b.rbs +0 -5
  247. data/smoke/const/test_expectations.yml +0 -134
  248. data/smoke/diagnostics/Steepfile +0 -6
  249. data/smoke/diagnostics/a.rbs +0 -22
  250. data/smoke/diagnostics/argument_type_mismatch.rb +0 -1
  251. data/smoke/diagnostics/block_body_type_mismatch.rb +0 -1
  252. data/smoke/diagnostics/block_type_mismatch.rb +0 -3
  253. data/smoke/diagnostics/break_type_mismatch.rb +0 -1
  254. data/smoke/diagnostics/different_method_parameter_kind.rb +0 -9
  255. data/smoke/diagnostics/else_on_exhaustive_case.rb +0 -12
  256. data/smoke/diagnostics/incompatible_annotation.rb +0 -6
  257. data/smoke/diagnostics/incompatible_argument.rb +0 -1
  258. data/smoke/diagnostics/incompatible_assignment.rb +0 -8
  259. data/smoke/diagnostics/method_arity_mismatch.rb +0 -11
  260. data/smoke/diagnostics/method_body_type_mismatch.rb +0 -6
  261. data/smoke/diagnostics/method_definition_missing.rb +0 -2
  262. data/smoke/diagnostics/method_parameter_mismatch.rb +0 -10
  263. data/smoke/diagnostics/method_return_type_annotation_mismatch.rb +0 -7
  264. data/smoke/diagnostics/missing_keyword.rb +0 -1
  265. data/smoke/diagnostics/no_method.rb +0 -1
  266. data/smoke/diagnostics/proc_type_expected.rb +0 -3
  267. data/smoke/diagnostics/required_block_missing.rb +0 -1
  268. data/smoke/diagnostics/return_type_mismatch.rb +0 -6
  269. data/smoke/diagnostics/test_expectations.yml +0 -591
  270. data/smoke/diagnostics/unexpected_block_given.rb +0 -1
  271. data/smoke/diagnostics/unexpected_dynamic_method.rb +0 -3
  272. data/smoke/diagnostics/unexpected_jump.rb +0 -4
  273. data/smoke/diagnostics/unexpected_jump_value.rb +0 -3
  274. data/smoke/diagnostics/unexpected_keyword.rb +0 -1
  275. data/smoke/diagnostics/unexpected_splat.rb +0 -1
  276. data/smoke/diagnostics/unexpected_yield.rb +0 -6
  277. data/smoke/diagnostics/unknown_constant_assigned.rb +0 -7
  278. data/smoke/diagnostics/unresolved_overloading.rb +0 -1
  279. data/smoke/diagnostics/unsupported_syntax.rb +0 -2
  280. data/smoke/diagnostics-rbs/Steepfile +0 -8
  281. data/smoke/diagnostics-rbs/duplicated-method-definition.rbs +0 -20
  282. data/smoke/diagnostics-rbs/generic-parameter-mismatch.rbs +0 -7
  283. data/smoke/diagnostics-rbs/inherit-module.rbs +0 -2
  284. data/smoke/diagnostics-rbs/invalid-method-overload.rbs +0 -3
  285. data/smoke/diagnostics-rbs/invalid-type-application.rbs +0 -7
  286. data/smoke/diagnostics-rbs/invalid_variance_annotation.rbs +0 -3
  287. data/smoke/diagnostics-rbs/mixin-class-error.rbs +0 -6
  288. data/smoke/diagnostics-rbs/nonregular-type-alias.rbs +0 -3
  289. data/smoke/diagnostics-rbs/recursive-alias.rbs +0 -5
  290. data/smoke/diagnostics-rbs/recursive-class.rbs +0 -8
  291. data/smoke/diagnostics-rbs/recursive-type-alias.rbs +0 -3
  292. data/smoke/diagnostics-rbs/superclass-mismatch.rbs +0 -7
  293. data/smoke/diagnostics-rbs/test_expectations.yml +0 -300
  294. data/smoke/diagnostics-rbs/unknown-method-alias.rbs +0 -3
  295. data/smoke/diagnostics-rbs/unknown-type-name-2.rbs +0 -5
  296. data/smoke/diagnostics-rbs/unknown-type-name.rbs +0 -13
  297. data/smoke/diagnostics-rbs-duplicated/Steepfile +0 -6
  298. data/smoke/diagnostics-rbs-duplicated/a.rbs +0 -5
  299. data/smoke/diagnostics-rbs-duplicated/test_expectations.yml +0 -13
  300. data/smoke/diagnostics-ruby-unsat/Steepfile +0 -6
  301. data/smoke/diagnostics-ruby-unsat/a.rbs +0 -3
  302. data/smoke/diagnostics-ruby-unsat/test_expectations.yml +0 -27
  303. data/smoke/diagnostics-ruby-unsat/unsatisfiable_constraint.rb +0 -6
  304. data/smoke/dstr/Steepfile +0 -6
  305. data/smoke/dstr/a.rb +0 -5
  306. data/smoke/dstr/test_expectations.yml +0 -13
  307. data/smoke/ensure/Steepfile +0 -6
  308. data/smoke/ensure/a.rb +0 -18
  309. data/smoke/ensure/test_expectations.yml +0 -62
  310. data/smoke/enumerator/Steepfile +0 -6
  311. data/smoke/enumerator/a.rb +0 -6
  312. data/smoke/enumerator/b.rb +0 -17
  313. data/smoke/enumerator/test_expectations.yml +0 -47
  314. data/smoke/extension/Steepfile +0 -6
  315. data/smoke/extension/a.rb +0 -10
  316. data/smoke/extension/a.rbs +0 -13
  317. data/smoke/extension/b.rb +0 -10
  318. data/smoke/extension/c.rb +0 -9
  319. data/smoke/extension/d.rb +0 -2
  320. data/smoke/extension/e.rb +0 -2
  321. data/smoke/extension/e.rbs +0 -7
  322. data/smoke/extension/f.rb +0 -2
  323. data/smoke/extension/f.rbs +0 -3
  324. data/smoke/extension/test_expectations.yml +0 -73
  325. data/smoke/hash/Steepfile +0 -6
  326. data/smoke/hash/a.rb +0 -17
  327. data/smoke/hash/a.rbs +0 -8
  328. data/smoke/hash/b.rb +0 -6
  329. data/smoke/hash/c.rb +0 -15
  330. data/smoke/hash/d.rb +0 -5
  331. data/smoke/hash/e.rb +0 -1
  332. data/smoke/hash/e.rbs +0 -3
  333. data/smoke/hash/f.rb +0 -11
  334. data/smoke/hash/test_expectations.yml +0 -81
  335. data/smoke/hello/Steepfile +0 -6
  336. data/smoke/hello/hello.rb +0 -11
  337. data/smoke/hello/hello.rbs +0 -7
  338. data/smoke/hello/test_expectations.yml +0 -25
  339. data/smoke/if/Steepfile +0 -6
  340. data/smoke/if/a.rb +0 -20
  341. data/smoke/if/test_expectations.yml +0 -34
  342. data/smoke/implements/Steepfile +0 -6
  343. data/smoke/implements/a.rb +0 -12
  344. data/smoke/implements/a.rbs +0 -6
  345. data/smoke/implements/b.rb +0 -13
  346. data/smoke/implements/b.rbs +0 -12
  347. data/smoke/implements/test_expectations.yml +0 -23
  348. data/smoke/initialize/Steepfile +0 -6
  349. data/smoke/initialize/a.rb +0 -12
  350. data/smoke/initialize/a.rbs +0 -3
  351. data/smoke/initialize/test_expectations.yml +0 -1
  352. data/smoke/integer/Steepfile +0 -6
  353. data/smoke/integer/a.rb +0 -26
  354. data/smoke/integer/test_expectations.yml +0 -110
  355. data/smoke/interface/Steepfile +0 -6
  356. data/smoke/interface/a.rb +0 -12
  357. data/smoke/interface/a.rbs +0 -12
  358. data/smoke/interface/test_expectations.yml +0 -23
  359. data/smoke/kwbegin/Steepfile +0 -6
  360. data/smoke/kwbegin/a.rb +0 -7
  361. data/smoke/kwbegin/test_expectations.yml +0 -17
  362. data/smoke/lambda/Steepfile +0 -6
  363. data/smoke/lambda/a.rb +0 -10
  364. data/smoke/lambda/test_expectations.yml +0 -17
  365. data/smoke/literal/Steepfile +0 -6
  366. data/smoke/literal/a.rb +0 -11
  367. data/smoke/literal/b.rb +0 -7
  368. data/smoke/literal/literal_methods.rbs +0 -4
  369. data/smoke/literal/test_expectations.yml +0 -106
  370. data/smoke/map/Steepfile +0 -6
  371. data/smoke/map/a.rb +0 -5
  372. data/smoke/map/test_expectations.yml +0 -1
  373. data/smoke/method/Steepfile +0 -6
  374. data/smoke/method/a.rb +0 -21
  375. data/smoke/method/a.rbs +0 -4
  376. data/smoke/method/b.rb +0 -25
  377. data/smoke/method/c.rb +0 -5
  378. data/smoke/method/d.rb +0 -1
  379. data/smoke/method/d.rbs +0 -3
  380. data/smoke/method/test_expectations.yml +0 -121
  381. data/smoke/module/Steepfile +0 -6
  382. data/smoke/module/a.rb +0 -19
  383. data/smoke/module/a.rbs +0 -16
  384. data/smoke/module/b.rb +0 -6
  385. data/smoke/module/c.rb +0 -22
  386. data/smoke/module/d.rb +0 -4
  387. data/smoke/module/e.rb +0 -13
  388. data/smoke/module/f.rb +0 -11
  389. data/smoke/module/test_expectations.yml +0 -75
  390. data/smoke/regexp/Steepfile +0 -6
  391. data/smoke/regexp/a.rb +0 -109
  392. data/smoke/regexp/b.rb +0 -79
  393. data/smoke/regexp/test_expectations.yml +0 -615
  394. data/smoke/regression/Steepfile +0 -6
  395. data/smoke/regression/array.rb +0 -7
  396. data/smoke/regression/block_param_split.rb +0 -7
  397. data/smoke/regression/block_param_split.rbs +0 -3
  398. data/smoke/regression/empty_yield.rb +0 -5
  399. data/smoke/regression/empty_yield.rbs +0 -3
  400. data/smoke/regression/enumerator_product.rb +0 -1
  401. data/smoke/regression/fun.rb +0 -8
  402. data/smoke/regression/fun.rbs +0 -4
  403. data/smoke/regression/hash.rb +0 -7
  404. data/smoke/regression/hello world.rb +0 -1
  405. data/smoke/regression/issue_328.rb +0 -1
  406. data/smoke/regression/issue_328.rbs +0 -0
  407. data/smoke/regression/issue_332.rb +0 -11
  408. data/smoke/regression/issue_332.rbs +0 -19
  409. data/smoke/regression/issue_372.rb +0 -8
  410. data/smoke/regression/issue_372.rbs +0 -4
  411. data/smoke/regression/lambda.rb +0 -3
  412. data/smoke/regression/masgn.rb +0 -4
  413. data/smoke/regression/poly_new.rb +0 -2
  414. data/smoke/regression/poly_new.rbs +0 -4
  415. data/smoke/regression/range.rb +0 -5
  416. data/smoke/regression/set_divide.rb +0 -12
  417. data/smoke/regression/test_expectations.yml +0 -120
  418. data/smoke/regression/thread.rb +0 -7
  419. data/smoke/rescue/Steepfile +0 -6
  420. data/smoke/rescue/a.rb +0 -48
  421. data/smoke/rescue/test_expectations.yml +0 -79
  422. data/smoke/self/Steepfile +0 -6
  423. data/smoke/self/a.rb +0 -21
  424. data/smoke/self/a.rbs +0 -4
  425. data/smoke/self/test_expectations.yml +0 -23
  426. data/smoke/skip/Steepfile +0 -6
  427. data/smoke/skip/skip.rb +0 -13
  428. data/smoke/skip/test_expectations.yml +0 -23
  429. data/smoke/stdout/Steepfile +0 -6
  430. data/smoke/stdout/a.rb +0 -8
  431. data/smoke/stdout/a.rbs +0 -7
  432. data/smoke/stdout/test_expectations.yml +0 -1
  433. data/smoke/super/Steepfile +0 -6
  434. data/smoke/super/a.rb +0 -30
  435. data/smoke/super/a.rbs +0 -10
  436. data/smoke/super/test_expectations.yml +0 -69
  437. data/smoke/toplevel/Steepfile +0 -6
  438. data/smoke/toplevel/a.rb +0 -3
  439. data/smoke/toplevel/a.rbs +0 -3
  440. data/smoke/toplevel/test_expectations.yml +0 -15
  441. data/smoke/tsort/Steepfile +0 -7
  442. data/smoke/tsort/a.rb +0 -12
  443. data/smoke/tsort/test_expectations.yml +0 -1
  444. data/smoke/type_case/Steepfile +0 -6
  445. data/smoke/type_case/a.rb +0 -24
  446. data/smoke/type_case/test_expectations.yml +0 -58
  447. data/smoke/unexpected/Steepfile +0 -6
  448. data/smoke/unexpected/test_expectations.yml +0 -13
  449. data/smoke/unexpected/unexpected.rbs +0 -3
  450. data/smoke/yield/Steepfile +0 -6
  451. data/smoke/yield/a.rb +0 -15
  452. data/smoke/yield/b.rb +0 -6
  453. data/smoke/yield/test_expectations.yml +0 -88
@@ -878,6 +878,7 @@ module Steep
878
878
  if self_type && method_context!.method
879
879
  if super_def = method_context!.super_method
880
880
  super_method = Interface::Shape::Entry.new(
881
+ private_method: true,
881
882
  method_types: super_def.defs.map {|type_def|
882
883
  decl = TypeInference::MethodCall::MethodDecl.new(
883
884
  method_name: InstanceMethodName.new(
@@ -1634,28 +1635,32 @@ module Steep
1634
1635
  when :yield
1635
1636
  if method_context && method_context.method_type
1636
1637
  if block_type = method_context.block_type
1637
- type = AST::Types::Proc.new(
1638
- type: block_type.type,
1639
- block: nil,
1640
- self_type: block_type.self_type
1641
- )
1642
- args = TypeInference::SendArgs.new(
1643
- node: node,
1644
- arguments: node.children,
1645
- type: type
1646
- )
1638
+ if block_type.type.params
1639
+ type = AST::Types::Proc.new(
1640
+ type: block_type.type,
1641
+ block: nil,
1642
+ self_type: block_type.self_type
1643
+ )
1644
+ args = TypeInference::SendArgs.new(
1645
+ node: node,
1646
+ arguments: node.children,
1647
+ type: type
1648
+ )
1647
1649
 
1648
- # @type var errors: Array[Diagnostic::Ruby::Base]
1649
- errors = []
1650
- constr = type_check_args(
1651
- nil,
1652
- args,
1653
- Subtyping::Constraints.new(unknowns: []),
1654
- errors
1655
- )
1650
+ # @type var errors: Array[Diagnostic::Ruby::Base]
1651
+ errors = []
1652
+ constr = type_check_args(
1653
+ nil,
1654
+ args,
1655
+ Subtyping::Constraints.new(unknowns: []),
1656
+ errors
1657
+ )
1656
1658
 
1657
- errors.each do |error|
1658
- typing.add_error(error)
1659
+ errors.each do |error|
1660
+ typing.add_error(error)
1661
+ end
1662
+ else
1663
+ constr = type_check_untyped_args(node.children)
1659
1664
  end
1660
1665
 
1661
1666
  add_typing(node, type: block_type.type.return_type)
@@ -1812,7 +1817,7 @@ module Steep
1812
1817
  .for_branch(right_node)
1813
1818
  .synthesize(right_node, hint: left_truthy.type, condition: true).to_ary
1814
1819
 
1815
- right_truthy, right_falsy = interpreter.eval(env: left_falsy.env, node: right_node)
1820
+ right_truthy, right_falsy = interpreter.eval(env: right_context.type_env, node: right_node)
1816
1821
 
1817
1822
  case
1818
1823
  when left_falsy.unreachable
@@ -1966,113 +1971,7 @@ module Steep
1966
1971
  interpreter = TypeInference::LogicTypeInterpreter.new(subtyping: checker, typing: typing, config: builder_config)
1967
1972
 
1968
1973
  if cond
1969
- branch_results = [] #: Array[Pair]
1970
-
1971
- cond_type, constr = constr.synthesize(cond)
1972
-
1973
- var_name = :"_a[#{SecureRandom.alphanumeric(4)}]"
1974
- var_cond, value_node = transform_condition_node(cond, var_name)
1975
- constr = constr.update_type_env {|env| env.assign_local_variable(var_name, cond_type, nil) }
1976
-
1977
- next_branch_reachable = true
1978
-
1979
- when_constr = constr
1980
- whens.each do |clause|
1981
- # @type var tests: Array[Parser::AST::Node]
1982
- # @type var body: Parser::AST::Node?
1983
- *tests, body = clause.children
1984
-
1985
- test_constr = when_constr
1986
- # @type var test_envs: Array[TypeInference::TypeEnv]
1987
- test_envs = []
1988
-
1989
- branch_reachable = false
1990
- false_branch_reachable = false
1991
-
1992
- tests.each do |test|
1993
- test_node = test.updated(:send, [test, :===, var_cond])
1994
- test_type, test_constr = test_constr.synthesize(test_node, condition: true).to_ary
1995
- truthy, falsy = interpreter.eval(node: test_node, env: test_constr.context.type_env)
1996
-
1997
- truthy_env = propagate_type_env(var_name, value_node, truthy.env)
1998
- falsy_env = propagate_type_env(var_name, value_node, falsy.env)
1999
-
2000
- test_envs << truthy_env
2001
-
2002
- test_constr = test_constr.update_type_env { falsy_env }
2003
-
2004
- branch_reachable ||= next_branch_reachable && !truthy.unreachable
2005
- false_branch_reachable = !falsy.unreachable
2006
- end
2007
-
2008
- next_branch_reachable &&= false_branch_reachable
2009
- body_constr = when_constr.update_type_env {|env| env.join(*test_envs) }
2010
-
2011
- branch_result =
2012
- if body
2013
- body_constr
2014
- .for_branch(body)
2015
- .tap {|constr| typing.add_context_for_node(body, context: constr.context) }
2016
- .synthesize(body, hint: hint)
2017
- else
2018
- Pair.new(type: AST::Builtin.nil_type, constr: body_constr)
2019
- end
2020
-
2021
- branch_results << branch_result
2022
-
2023
- if !branch_reachable && !branch_result.type.is_a?(AST::Types::Bot)
2024
- typing.add_error(
2025
- Diagnostic::Ruby::UnreachableValueBranch.new(
2026
- node: clause,
2027
- type: branch_result.type,
2028
- location: clause.location.keyword
2029
- )
2030
- )
2031
- end
2032
-
2033
- when_constr = test_constr
2034
- end
2035
-
2036
- if els
2037
- node.loc.else or raise
2038
-
2039
- begin_pos = node.loc.else.end_pos
2040
- end_pos = node.loc.end.begin_pos
2041
- typing.add_context(begin_pos..end_pos, context: when_constr.context)
2042
-
2043
- else_result = when_constr.synthesize(els, hint: hint)
2044
-
2045
- if next_branch_reachable
2046
- branch_results << else_result
2047
- end
2048
- end
2049
-
2050
- types = branch_results.map(&:type)
2051
- constrs = branch_results.map(&:constr)
2052
-
2053
- if !next_branch_reachable
2054
- # Exhaustive
2055
- _, _, _, loc = deconstruct_case_node!(node)
2056
-
2057
- # `else` may present even if it's empty
2058
- if loc.else
2059
- if els
2060
- else_result or raise
2061
- unless else_result.type.is_a?(AST::Types::Bot)
2062
- typing.add_error Diagnostic::Ruby::UnreachableValueBranch.new(
2063
- node: els,
2064
- type: else_result.type,
2065
- location: node.loc.else || raise
2066
- )
2067
- end
2068
- end
2069
- end
2070
- else
2071
- unless els
2072
- constrs << when_constr
2073
- types << AST::Builtin.nil_type
2074
- end
2075
- end
1974
+ types, envs = TypeInference::CaseWhen.type_check(constr, node, interpreter, hint: hint, condition: condition)
2076
1975
  else
2077
1976
  branch_results = [] #: Array[Pair]
2078
1977
 
@@ -2131,7 +2030,7 @@ module Steep
2131
2030
  end
2132
2031
 
2133
2032
  types = branch_results.map(&:type)
2134
- constrs = branch_results.map(&:constr)
2033
+ envs = branch_results.map {|result| result.constr.context.type_env }
2135
2034
 
2136
2035
  unless els
2137
2036
  types << AST::Builtin.nil_type
@@ -2139,7 +2038,6 @@ module Steep
2139
2038
  end
2140
2039
 
2141
2040
  constr = constr.update_type_env do |env|
2142
- envs = constrs.map {|c| c.context.type_env }
2143
2041
  env.join(*envs)
2144
2042
  end
2145
2043
 
@@ -2208,6 +2106,7 @@ module Steep
2208
2106
  end
2209
2107
 
2210
2108
  if body
2109
+ resbody_construction.typing.add_context_for_node(body, context: resbody_construction.context)
2211
2110
  resbody_construction.synthesize(body, hint: hint)
2212
2111
  else
2213
2112
  Pair.new(constr: body_constr, type: AST::Builtin.nil_type)
@@ -2278,10 +2177,21 @@ module Steep
2278
2177
  var_type = AST::Builtin.any_type
2279
2178
  else
2280
2179
  if each = calculate_interface(collection_type, :each, private: true)
2281
- if method_type = (each.method_types || []).find {|type| type.block && type.block.type.params.first_param }
2180
+ method_type = (each.method_types || []).find do |type|
2181
+ if type.block
2182
+ if type.block.type.params
2183
+ type.block.type.params.first_param
2184
+ else
2185
+ true
2186
+ end
2187
+ end
2188
+ end
2189
+ if method_type
2282
2190
  if block = method_type.block
2283
- if first_param = block.type.params.first_param
2191
+ if first_param = block.type&.params&.first_param
2284
2192
  var_type = first_param.type #: AST::Types::t
2193
+ else
2194
+ var_type - AST::Builtin.any_type
2285
2195
  end
2286
2196
  end
2287
2197
  end
@@ -2455,11 +2365,8 @@ module Steep
2455
2365
  end
2456
2366
 
2457
2367
  when :defined?
2458
- each_child_node(node) do |child|
2459
- synthesize(child)
2460
- end
2461
-
2462
- add_typing(node, type: AST::Builtin.any_type)
2368
+ type_any_rec(node, only_children: true)
2369
+ add_typing(node, type: AST::Builtin.optional(AST::Builtin::String.instance_type))
2463
2370
 
2464
2371
  when :gvasgn
2465
2372
  yield_self do
@@ -2495,31 +2402,33 @@ module Steep
2495
2402
 
2496
2403
  if hint.is_a?(AST::Types::Proc) && value_node.type == :sym
2497
2404
  if hint.one_arg?
2498
- # Assumes Symbol#to_proc implementation
2499
- param_type = hint.type.params.required[0]
2500
- case param_type
2501
- when AST::Types::Any
2502
- type = AST::Types::Any.new
2503
- else
2504
- if method = calculate_interface(param_type, private: true)&.methods&.[](value_node.children[0])
2505
- return_types = method.method_types.filter_map do |method_type|
2506
- if method_type.type.params.optional?
2507
- method_type.type.return_type
2405
+ if hint.type.params
2406
+ # Assumes Symbol#to_proc implementation
2407
+ param_type = hint.type.params.required[0]
2408
+ case param_type
2409
+ when AST::Types::Any
2410
+ type = AST::Types::Any.new
2411
+ else
2412
+ if method = calculate_interface(param_type, private: true)&.methods&.[](value_node.children[0])
2413
+ return_types = method.method_types.filter_map do |method_type|
2414
+ if method_type.type.params.nil? || method_type.type.params.optional?
2415
+ method_type.type.return_type
2416
+ end
2508
2417
  end
2509
- end
2510
2418
 
2511
- unless return_types.empty?
2512
- type = AST::Types::Proc.new(
2513
- type: Interface::Function.new(
2514
- params: Interface::Function::Params.empty.with_first_param(
2515
- Interface::Function::Params::PositionalParams::Required.new(param_type)
2419
+ unless return_types.empty?
2420
+ type = AST::Types::Proc.new(
2421
+ type: Interface::Function.new(
2422
+ params: Interface::Function::Params.empty.with_first_param(
2423
+ Interface::Function::Params::PositionalParams::Required.new(param_type)
2424
+ ),
2425
+ return_type: return_types[0],
2426
+ location: nil
2516
2427
  ),
2517
- return_type: return_types[0],
2518
- location: nil
2519
- ),
2520
- block: nil,
2521
- self_type: nil
2522
- )
2428
+ block: nil,
2429
+ self_type: nil
2430
+ )
2431
+ end
2523
2432
  end
2524
2433
  end
2525
2434
  end
@@ -2721,6 +2630,7 @@ module Steep
2721
2630
  end
2722
2631
  end
2723
2632
  rescue RBS::BaseError => exn
2633
+ Steep.logger.warn("hello")
2724
2634
  Steep.logger.warn { "Unexpected RBS error: #{exn.message}" }
2725
2635
  exn.backtrace&.each {|loc| Steep.logger.warn " #{loc}" }
2726
2636
  typing.add_error(Diagnostic::Ruby::UnexpectedError.new(node: node, error: exn))
@@ -3294,7 +3204,7 @@ module Steep
3294
3204
  end
3295
3205
 
3296
3206
  def type_send_interface(node, interface:, receiver:, receiver_type:, method_name:, arguments:, block_params:, block_body:, tapp:, hint:)
3297
- method = interface&.methods&.[](method_name)
3207
+ method = interface.methods[method_name]
3298
3208
 
3299
3209
  if method
3300
3210
  call, constr = type_method_call(
@@ -3541,16 +3451,16 @@ module Steep
3541
3451
  self_type: self_type,
3542
3452
  class_type: module_context.module_type,
3543
3453
  instance_type: module_context.instance_type,
3544
- variable_bounds: variable_context.upper_bounds
3454
+ variable_bounds: context.variable_context.upper_bounds
3545
3455
  )
3546
3456
  end
3547
3457
 
3548
3458
  def calculate_interface(type, method_name = nil, private:)
3549
- shape = checker.builder.shape(
3550
- type,
3551
- public_only: !private,
3552
- config: builder_config
3553
- )
3459
+ shape = checker.builder.shape(type, builder_config)
3460
+
3461
+ unless private
3462
+ shape = shape&.public_shape
3463
+ end
3554
3464
 
3555
3465
  if method_name
3556
3466
  if shape
@@ -3732,10 +3642,6 @@ module Steep
3732
3642
  end
3733
3643
  end
3734
3644
 
3735
- def inspect
3736
- "#<#{self.class}>"
3737
- end
3738
-
3739
3645
  def with_child_typing(range:)
3740
3646
  constr = with_new_typing(typing.new_child(range))
3741
3647
 
@@ -4027,13 +3933,17 @@ module Steep
4027
3933
  # @type var errors: Array[Diagnostic::Ruby::Base]
4028
3934
  errors = []
4029
3935
 
4030
- args = TypeInference::SendArgs.new(node: node, arguments: arguments, type: method_type)
4031
- constr = constr.type_check_args(
4032
- method_name,
4033
- args,
4034
- constraints,
4035
- errors
4036
- )
3936
+ if method_type.type.params
3937
+ args = TypeInference::SendArgs.new(node: node, arguments: arguments, type: method_type)
3938
+ constr = constr.type_check_args(
3939
+ method_name,
3940
+ args,
3941
+ constraints,
3942
+ errors
3943
+ )
3944
+ else
3945
+ constr = constr.type_check_untyped_args(arguments)
3946
+ end
4037
3947
 
4038
3948
  if block_params
4039
3949
  # block is given
@@ -4122,11 +4032,12 @@ module Steep
4122
4032
  end
4123
4033
 
4124
4034
  method_type, solved, s = apply_solution(errors, node: node, method_type: method_type) {
4125
- constraints.solution(
4126
- checker,
4127
- variables: method_type.type.params.free_variables + method_type.block.type.params.free_variables,
4128
- context: ccontext
4129
- )
4035
+ fvs_ = Set[] #: Set[AST::Types::variable]
4036
+
4037
+ fvs_.merge(method_type.type.params.free_variables) if method_type.type.params
4038
+ fvs_.merge(method_type.block.type.params.free_variables) if method_type.block.type.params
4039
+
4040
+ constraints.solution(checker, variables: fvs_, context: ccontext)
4130
4041
  }
4131
4042
 
4132
4043
  method_type.block or raise
@@ -4214,129 +4125,143 @@ module Steep
4214
4125
  return_type = method_type.type.return_type
4215
4126
  end
4216
4127
  else
4217
- # Block is given but method doesn't accept
4218
- #
4219
- constr.type_block_without_hint(node: node, block_annotations: block_annotations, block_params: block_params_, block_body: block_body) do |error|
4220
- errors << error
4221
- end
4128
+ if args
4129
+ # Block is given but method doesn't accept
4130
+ #
4131
+ constr.type_block_without_hint(node: node, block_annotations: block_annotations, block_params: block_params_, block_body: block_body) do |error|
4132
+ errors << error
4133
+ end
4222
4134
 
4223
- case node.children[0].type
4224
- when :super, :zsuper
4225
- unless method_context!.super_method
4226
- errors << Diagnostic::Ruby::UnexpectedSuper.new(
4227
- node: node.children[0],
4228
- method: method_name
4135
+ case node.children[0].type
4136
+ when :super, :zsuper
4137
+ unless method_context!.super_method
4138
+ errors << Diagnostic::Ruby::UnexpectedSuper.new(
4139
+ node: node.children[0],
4140
+ method: method_name
4141
+ )
4142
+ end
4143
+ else
4144
+ errors << Diagnostic::Ruby::UnexpectedBlockGiven.new(
4145
+ node: node,
4146
+ method_type: method_type
4229
4147
  )
4230
4148
  end
4149
+
4150
+ method_type = eliminate_vars(method_type, type_param_names)
4151
+ return_type = method_type.type.return_type
4231
4152
  else
4232
- errors << Diagnostic::Ruby::UnexpectedBlockGiven.new(
4233
- node: node,
4234
- method_type: method_type
4235
- )
4153
+ if block_body
4154
+ block_annotations = source.annotations(block: node, factory: checker.factory, context: nesting)
4155
+ type_block_without_hint(
4156
+ node: node,
4157
+ block_annotations: block_annotations,
4158
+ block_params: TypeInference::BlockParams.from_node(block_params, annotations: block_annotations),
4159
+ block_body: block_body
4160
+ )
4161
+ end
4236
4162
  end
4237
-
4238
- method_type = eliminate_vars(method_type, type_param_names)
4239
- return_type = method_type.type.return_type
4240
4163
  end
4241
4164
  else
4242
4165
  # Block syntax is not given
4243
- arg = args.block_pass_arg
4166
+ if args
4167
+ arg = args.block_pass_arg
4244
4168
 
4245
- case
4246
- when forwarded_args_node = args.forwarded_args_node
4247
- (_, block = method_context!.forward_arg_type) or raise
4169
+ case
4170
+ when forwarded_args_node = args.forwarded_args_node
4171
+ (_, block = method_context!.forward_arg_type) or raise
4248
4172
 
4249
- method_block_type = method_type.block&.to_proc_type || AST::Builtin.nil_type
4250
- forwarded_block_type = block&.to_proc_type || AST::Builtin.nil_type
4173
+ method_block_type = method_type.block&.to_proc_type || AST::Builtin.nil_type
4174
+ forwarded_block_type = block&.to_proc_type || AST::Builtin.nil_type
4251
4175
 
4252
- if result = constr.no_subtyping?(sub_type: forwarded_block_type, super_type: method_block_type)
4253
- errors << Diagnostic::Ruby::IncompatibleArgumentForwarding.new(
4254
- method_name: method_name,
4255
- node: forwarded_args_node,
4256
- block_pair: [block, method_type.block],
4257
- result: result
4258
- )
4259
- end
4176
+ if result = constr.no_subtyping?(sub_type: forwarded_block_type, super_type: method_block_type)
4177
+ errors << Diagnostic::Ruby::IncompatibleArgumentForwarding.new(
4178
+ method_name: method_name,
4179
+ node: forwarded_args_node,
4180
+ block_pair: [block, method_type.block],
4181
+ result: result
4182
+ )
4183
+ end
4260
4184
 
4261
- when arg.compatible?
4262
- if arg.node
4263
- # Block pass (&block) is given
4264
- node_type, constr = constr.synthesize(arg.node, hint: arg.node_type)
4185
+ when arg.compatible?
4186
+ if arg.node
4187
+ # Block pass (&block) is given
4188
+ node_type, constr = constr.synthesize(arg.node, hint: arg.node_type)
4265
4189
 
4266
- nil_given =
4267
- constr.check_relation(sub_type: node_type, super_type: AST::Builtin.nil_type).success? &&
4268
- !node_type.is_a?(AST::Types::Any)
4190
+ nil_given =
4191
+ constr.check_relation(sub_type: node_type, super_type: AST::Builtin.nil_type).success? &&
4192
+ !node_type.is_a?(AST::Types::Any)
4269
4193
 
4270
- if nil_given
4271
- # nil is given ==> no block arg node is given
4272
- method_type, solved, _ = apply_solution(errors, node: node, method_type: method_type) {
4273
- constraints.solution(checker, variables: method_type.free_variables, context: ccontext)
4274
- }
4275
- method_type = eliminate_vars(method_type, type_param_names) unless solved
4194
+ if nil_given
4195
+ # nil is given ==> no block arg node is given
4196
+ method_type, solved, _ = apply_solution(errors, node: node, method_type: method_type) {
4197
+ constraints.solution(checker, variables: method_type.free_variables, context: ccontext)
4198
+ }
4199
+ method_type = eliminate_vars(method_type, type_param_names) unless solved
4276
4200
 
4277
- # Passing no block
4278
- errors << Diagnostic::Ruby::RequiredBlockMissing.new(
4279
- node: node,
4280
- method_type: method_type
4281
- )
4282
- else
4283
- # non-nil value is given
4284
- constr.check_relation(sub_type: node_type, super_type: arg.node_type, constraints: constraints).else do |result|
4285
- errors << Diagnostic::Ruby::BlockTypeMismatch.new(
4286
- node: arg.node,
4287
- expected: arg.node_type,
4288
- actual: node_type,
4289
- result: result
4201
+ # Passing no block
4202
+ errors << Diagnostic::Ruby::RequiredBlockMissing.new(
4203
+ node: node,
4204
+ method_type: method_type
4290
4205
  )
4291
- end
4206
+ else
4207
+ # non-nil value is given
4208
+ constr.check_relation(sub_type: node_type, super_type: arg.node_type, constraints: constraints).else do |result|
4209
+ errors << Diagnostic::Ruby::BlockTypeMismatch.new(
4210
+ node: arg.node,
4211
+ expected: arg.node_type,
4212
+ actual: node_type,
4213
+ result: result
4214
+ )
4215
+ end
4292
4216
 
4217
+ method_type, solved, _ = apply_solution(errors, node: node, method_type: method_type) {
4218
+ constraints.solution(checker, variables: method_type.free_variables, context: ccontext)
4219
+ }
4220
+ method_type = eliminate_vars(method_type, type_param_names) unless solved
4221
+ end
4222
+ else
4223
+ # Block is not given
4293
4224
  method_type, solved, _ = apply_solution(errors, node: node, method_type: method_type) {
4294
4225
  constraints.solution(checker, variables: method_type.free_variables, context: ccontext)
4295
4226
  }
4296
4227
  method_type = eliminate_vars(method_type, type_param_names) unless solved
4297
4228
  end
4298
- else
4299
- # Block is not given
4229
+
4230
+ return_type = method_type.type.return_type
4231
+
4232
+ when arg.block_missing?
4233
+ # Block is required but not given
4300
4234
  method_type, solved, _ = apply_solution(errors, node: node, method_type: method_type) {
4301
4235
  constraints.solution(checker, variables: method_type.free_variables, context: ccontext)
4302
4236
  }
4303
- method_type = eliminate_vars(method_type, type_param_names) unless solved
4304
- end
4305
4237
 
4306
- return_type = method_type.type.return_type
4307
-
4308
- when arg.block_missing?
4309
- # Block is required but not given
4310
- method_type, solved, _ = apply_solution(errors, node: node, method_type: method_type) {
4311
- constraints.solution(checker, variables: method_type.free_variables, context: ccontext)
4312
- }
4313
-
4314
- method_type = eliminate_vars(method_type, type_param_names) unless solved
4315
- return_type = method_type.type.return_type
4238
+ method_type = eliminate_vars(method_type, type_param_names) unless solved
4239
+ return_type = method_type.type.return_type
4316
4240
 
4317
- errors << Diagnostic::Ruby::RequiredBlockMissing.new(
4318
- node: node,
4319
- method_type: method_type
4320
- )
4241
+ errors << Diagnostic::Ruby::RequiredBlockMissing.new(
4242
+ node: node,
4243
+ method_type: method_type
4244
+ )
4321
4245
 
4322
- when arg.unexpected_block?
4323
- # Unexpected block pass node is given
4246
+ when arg.unexpected_block?
4247
+ # Unexpected block pass node is given
4324
4248
 
4325
- arg.node or raise
4249
+ arg.node or raise
4326
4250
 
4327
- method_type, solved, _ = apply_solution(errors, node: node, method_type: method_type) {
4328
- constraints.solution(checker, variables: method_type.free_variables, context: ccontext)
4329
- }
4330
- method_type = eliminate_vars(method_type, type_param_names) unless solved
4331
- return_type = method_type.type.return_type
4251
+ method_type, solved, _ = apply_solution(errors, node: node, method_type: method_type) {
4252
+ constraints.solution(checker, variables: method_type.free_variables, context: ccontext)
4253
+ }
4254
+ method_type = eliminate_vars(method_type, type_param_names) unless solved
4255
+ return_type = method_type.type.return_type
4332
4256
 
4333
- node_type, constr = constr.synthesize(arg.node)
4257
+ node_type, constr = constr.synthesize(arg.node)
4334
4258
 
4335
- unless constr.check_relation(sub_type: node_type, super_type: AST::Builtin.nil_type).success?
4336
- errors << Diagnostic::Ruby::UnexpectedBlockGiven.new(
4337
- node: node,
4338
- method_type: method_type
4339
- )
4259
+ unless constr.check_relation(sub_type: node_type, super_type: AST::Builtin.nil_type).success?
4260
+ errors << Diagnostic::Ruby::UnexpectedBlockGiven.new(
4261
+ node: node,
4262
+ method_type: method_type
4263
+ )
4264
+ end
4340
4265
  end
4341
4266
  end
4342
4267
  end
@@ -4463,7 +4388,7 @@ module Steep
4463
4388
  def for_block(body_node, block_params:, block_param_hint:, block_type_hint:, block_block_hint:, block_annotations:, node_type_hint:, block_self_hint:)
4464
4389
  block_param_pairs = block_param_hint && block_params.zip(block_param_hint, block_block_hint, factory: checker.factory)
4465
4390
 
4466
- # @type var param_types_hash: Hash[Symbol, AST::Types::t]
4391
+ # @type var param_types_hash: Hash[Symbol?, AST::Types::t]
4467
4392
  param_types_hash = {}
4468
4393
  if block_param_pairs
4469
4394
  block_param_pairs.each do |param, type|
@@ -4498,10 +4423,12 @@ module Steep
4498
4423
  end
4499
4424
  end
4500
4425
 
4501
- param_types_hash.delete_if {|name, _| SPECIAL_LVAR_NAMES.include?(name) }
4426
+ param_types_hash.delete_if {|name, _| name && SPECIAL_LVAR_NAMES.include?(name) }
4502
4427
 
4503
4428
  param_types = param_types_hash.each.with_object({}) do |pair, hash| #$ Hash[Symbol, [AST::Types::t, AST::Types::t?]]
4504
4429
  name, type = pair
4430
+ # skip unamed arguments `*`, `**` and `&`
4431
+ next if name.nil?
4505
4432
  hash[name] = [type, nil]
4506
4433
  end
4507
4434
 
@@ -4774,8 +4701,8 @@ module Steep
4774
4701
  !nodes.empty? && nodes.all? {|child| child.type == :class || child.type == :module}
4775
4702
  end
4776
4703
 
4777
- def type_any_rec(node)
4778
- add_typing node, type: AST::Builtin.any_type
4704
+ def type_any_rec(node, only_children: false)
4705
+ add_typing node, type: AST::Builtin.any_type unless only_children
4779
4706
 
4780
4707
  each_child_node(node) do |child|
4781
4708
  type_any_rec(child)
@@ -4906,7 +4833,7 @@ module Steep
4906
4833
  if shape = calculate_interface(type, private: false)
4907
4834
  if entry = shape.methods[method]
4908
4835
  method_type = entry.method_types.find do |method_type|
4909
- method_type.type.params.optional?
4836
+ method_type.type.params.nil? || method_type.type.params.optional?
4910
4837
  end
4911
4838
 
4912
4839
  method_type.type.return_type if method_type
@@ -5162,22 +5089,6 @@ module Steep
5162
5089
  with_new_typing(typing.parent || raise)
5163
5090
  end
5164
5091
 
5165
- def transform_condition_node(node, var_name)
5166
- case node.type
5167
- when :lvasgn
5168
- name, rhs = node.children
5169
- rhs, value_node = transform_condition_node(rhs, var_name)
5170
- [node.updated(nil, [name, rhs]), value_node]
5171
- when :begin
5172
- *children, last = node.children
5173
- last, value_node = transform_condition_node(last, var_name)
5174
- [node.updated(nil, children.push(last)), value_node]
5175
- else
5176
- var_node = node.updated(:lvar, [var_name])
5177
- [var_node, node]
5178
- end
5179
- end
5180
-
5181
5092
  def type_name(type)
5182
5093
  case type
5183
5094
  when AST::Types::Name::Instance, AST::Types::Name::Singleton
@@ -5228,20 +5139,5 @@ module Steep
5228
5139
  end
5229
5140
  end
5230
5141
  end
5231
-
5232
- def propagate_type_env(source, dest, env)
5233
- source_type = env[source] or raise
5234
-
5235
- if dest.type == :lvar
5236
- var_name = dest.children[0] #: Symbol
5237
- env.assign_local_variable(var_name, source_type, nil)
5238
- else
5239
- if env[dest]
5240
- env.replace_pure_call_type(dest, source_type)
5241
- else
5242
- env
5243
- end
5244
- end
5245
- end
5246
5142
  end
5247
5143
  end