rbs 4.1.0.pre.2-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (574) hide show
  1. checksums.yaml +7 -0
  2. data/.clang-format +75 -0
  3. data/.clangd +2 -0
  4. data/.github/dependabot.yml +24 -0
  5. data/.github/workflows/bundle-update.yml +63 -0
  6. data/.github/workflows/c-check.yml +61 -0
  7. data/.github/workflows/comments.yml +37 -0
  8. data/.github/workflows/dependabot.yml +30 -0
  9. data/.github/workflows/jruby.yml +67 -0
  10. data/.github/workflows/milestone.yml +83 -0
  11. data/.github/workflows/ruby.yml +158 -0
  12. data/.github/workflows/rust.yml +184 -0
  13. data/.github/workflows/truffleruby.yml +54 -0
  14. data/.github/workflows/typecheck.yml +39 -0
  15. data/.github/workflows/wasm.yml +53 -0
  16. data/.github/workflows/windows.yml +49 -0
  17. data/.gitignore +38 -0
  18. data/.rubocop.yml +72 -0
  19. data/BSDL +22 -0
  20. data/CHANGELOG.md +2292 -0
  21. data/COPYING +56 -0
  22. data/README.md +240 -0
  23. data/Rakefile +869 -0
  24. data/Steepfile +53 -0
  25. data/config.yml +913 -0
  26. data/core/array.rbs +4142 -0
  27. data/core/basic_object.rbs +376 -0
  28. data/core/binding.rbs +148 -0
  29. data/core/builtin.rbs +278 -0
  30. data/core/class.rbs +223 -0
  31. data/core/comparable.rbs +192 -0
  32. data/core/complex.rbs +812 -0
  33. data/core/constants.rbs +96 -0
  34. data/core/data.rbs +415 -0
  35. data/core/dir.rbs +993 -0
  36. data/core/encoding.rbs +1368 -0
  37. data/core/enumerable.rbs +2506 -0
  38. data/core/enumerator/arithmetic_sequence.rbs +70 -0
  39. data/core/enumerator/product.rbs +92 -0
  40. data/core/enumerator.rbs +705 -0
  41. data/core/env.rbs +6 -0
  42. data/core/errno.rbs +682 -0
  43. data/core/errors.rbs +789 -0
  44. data/core/exception.rbs +485 -0
  45. data/core/false_class.rbs +82 -0
  46. data/core/fiber.rbs +570 -0
  47. data/core/fiber_error.rbs +11 -0
  48. data/core/file.rbs +2045 -0
  49. data/core/file_constants.rbs +463 -0
  50. data/core/file_stat.rbs +534 -0
  51. data/core/file_test.rbs +331 -0
  52. data/core/float.rbs +1316 -0
  53. data/core/gc.rbs +788 -0
  54. data/core/global_variables.rbs +184 -0
  55. data/core/hash.rbs +2183 -0
  56. data/core/integer.rbs +1374 -0
  57. data/core/io/buffer.rbs +995 -0
  58. data/core/io/wait.rbs +48 -0
  59. data/core/io.rbs +3472 -0
  60. data/core/kernel.rbs +3172 -0
  61. data/core/marshal.rbs +207 -0
  62. data/core/match_data.rbs +637 -0
  63. data/core/math.rbs +770 -0
  64. data/core/method.rbs +422 -0
  65. data/core/module.rbs +1856 -0
  66. data/core/nil_class.rbs +210 -0
  67. data/core/numeric.rbs +832 -0
  68. data/core/object.rbs +108 -0
  69. data/core/object_space/weak_key_map.rbs +166 -0
  70. data/core/object_space.rbs +197 -0
  71. data/core/pathname.rbs +1322 -0
  72. data/core/proc.rbs +905 -0
  73. data/core/process.rbs +2316 -0
  74. data/core/ractor.rbs +924 -0
  75. data/core/random.rbs +255 -0
  76. data/core/range.rbs +1209 -0
  77. data/core/rational.rbs +502 -0
  78. data/core/rb_config.rbs +88 -0
  79. data/core/rbs/ops.rbs +154 -0
  80. data/core/rbs/unnamed/argf.rbs +1236 -0
  81. data/core/rbs/unnamed/env_class.rbs +1214 -0
  82. data/core/rbs/unnamed/main_class.rbs +123 -0
  83. data/core/rbs/unnamed/random.rbs +186 -0
  84. data/core/refinement.rbs +59 -0
  85. data/core/regexp.rbs +1974 -0
  86. data/core/ruby.rbs +53 -0
  87. data/core/ruby_vm.rbs +809 -0
  88. data/core/rubygems/basic_specification.rbs +6 -0
  89. data/core/rubygems/config_file.rbs +38 -0
  90. data/core/rubygems/dependency_installer.rbs +6 -0
  91. data/core/rubygems/errors.rbs +109 -0
  92. data/core/rubygems/installer.rbs +15 -0
  93. data/core/rubygems/path_support.rbs +6 -0
  94. data/core/rubygems/platform.rbs +7 -0
  95. data/core/rubygems/request_set.rbs +49 -0
  96. data/core/rubygems/requirement.rbs +148 -0
  97. data/core/rubygems/rubygems.rbs +1105 -0
  98. data/core/rubygems/source_list.rbs +15 -0
  99. data/core/rubygems/specification.rbs +23 -0
  100. data/core/rubygems/stream_ui.rbs +5 -0
  101. data/core/rubygems/uninstaller.rbs +10 -0
  102. data/core/rubygems/version.rbs +293 -0
  103. data/core/set.rbs +751 -0
  104. data/core/signal.rbs +110 -0
  105. data/core/string.rbs +5532 -0
  106. data/core/struct.rbs +668 -0
  107. data/core/symbol.rbs +482 -0
  108. data/core/thread.rbs +1826 -0
  109. data/core/thread_group.rbs +79 -0
  110. data/core/time.rbs +1793 -0
  111. data/core/trace_point.rbs +483 -0
  112. data/core/true_class.rbs +98 -0
  113. data/core/unbound_method.rbs +337 -0
  114. data/core/warning.rbs +87 -0
  115. data/docs/CONTRIBUTING.md +107 -0
  116. data/docs/aliases.md +79 -0
  117. data/docs/architecture.md +110 -0
  118. data/docs/collection.md +192 -0
  119. data/docs/config.md +171 -0
  120. data/docs/data_and_struct.md +86 -0
  121. data/docs/encoding.md +56 -0
  122. data/docs/gem.md +56 -0
  123. data/docs/inline.md +634 -0
  124. data/docs/rbs_by_example.md +309 -0
  125. data/docs/repo.md +125 -0
  126. data/docs/rust.md +96 -0
  127. data/docs/sigs.md +167 -0
  128. data/docs/stdlib.md +147 -0
  129. data/docs/syntax.md +940 -0
  130. data/docs/tools.md +17 -0
  131. data/docs/type_fingerprint.md +21 -0
  132. data/docs/wasm_serialization.md +80 -0
  133. data/exe/rbs +7 -0
  134. data/ext/rbs_extension/ast_translation.c +1855 -0
  135. data/ext/rbs_extension/ast_translation.h +41 -0
  136. data/ext/rbs_extension/class_constants.c +187 -0
  137. data/ext/rbs_extension/class_constants.h +104 -0
  138. data/ext/rbs_extension/compat.h +10 -0
  139. data/ext/rbs_extension/extconf.rb +40 -0
  140. data/ext/rbs_extension/legacy_location.c +294 -0
  141. data/ext/rbs_extension/legacy_location.h +82 -0
  142. data/ext/rbs_extension/main.c +613 -0
  143. data/ext/rbs_extension/rbs_extension.h +16 -0
  144. data/ext/rbs_extension/rbs_string_bridging.c +9 -0
  145. data/ext/rbs_extension/rbs_string_bridging.h +24 -0
  146. data/goodcheck.yml +91 -0
  147. data/include/rbs/ast.h +1047 -0
  148. data/include/rbs/defines.h +99 -0
  149. data/include/rbs/lexer.h +207 -0
  150. data/include/rbs/location.h +40 -0
  151. data/include/rbs/parser.h +153 -0
  152. data/include/rbs/serialize.h +39 -0
  153. data/include/rbs/string.h +47 -0
  154. data/include/rbs/util/rbs_allocator.h +59 -0
  155. data/include/rbs/util/rbs_assert.h +20 -0
  156. data/include/rbs/util/rbs_buffer.h +83 -0
  157. data/include/rbs/util/rbs_constant_pool.h +155 -0
  158. data/include/rbs/util/rbs_encoding.h +282 -0
  159. data/include/rbs/util/rbs_unescape.h +24 -0
  160. data/include/rbs.h +14 -0
  161. data/lib/rbs/ancestor_graph.rb +92 -0
  162. data/lib/rbs/annotate/annotations.rb +199 -0
  163. data/lib/rbs/annotate/formatter.rb +82 -0
  164. data/lib/rbs/annotate/rdoc_annotator.rb +398 -0
  165. data/lib/rbs/annotate/rdoc_source.rb +131 -0
  166. data/lib/rbs/annotate.rb +8 -0
  167. data/lib/rbs/ast/annotation.rb +29 -0
  168. data/lib/rbs/ast/comment.rb +29 -0
  169. data/lib/rbs/ast/declarations.rb +472 -0
  170. data/lib/rbs/ast/directives.rb +49 -0
  171. data/lib/rbs/ast/members.rb +451 -0
  172. data/lib/rbs/ast/ruby/annotations.rb +451 -0
  173. data/lib/rbs/ast/ruby/comment_block.rb +247 -0
  174. data/lib/rbs/ast/ruby/declarations.rb +291 -0
  175. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +28 -0
  176. data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
  177. data/lib/rbs/ast/ruby/members.rb +762 -0
  178. data/lib/rbs/ast/type_param.rb +235 -0
  179. data/lib/rbs/ast/visitor.rb +137 -0
  180. data/lib/rbs/buffer.rb +189 -0
  181. data/lib/rbs/builtin_names.rb +58 -0
  182. data/lib/rbs/cli/colored_io.rb +48 -0
  183. data/lib/rbs/cli/diff.rb +84 -0
  184. data/lib/rbs/cli/validate.rb +294 -0
  185. data/lib/rbs/cli.rb +1253 -0
  186. data/lib/rbs/collection/cleaner.rb +38 -0
  187. data/lib/rbs/collection/config/lockfile.rb +92 -0
  188. data/lib/rbs/collection/config/lockfile_generator.rb +269 -0
  189. data/lib/rbs/collection/config.rb +81 -0
  190. data/lib/rbs/collection/installer.rb +32 -0
  191. data/lib/rbs/collection/sources/base.rb +14 -0
  192. data/lib/rbs/collection/sources/git.rb +265 -0
  193. data/lib/rbs/collection/sources/local.rb +81 -0
  194. data/lib/rbs/collection/sources/rubygems.rb +48 -0
  195. data/lib/rbs/collection/sources/stdlib.rb +50 -0
  196. data/lib/rbs/collection/sources.rb +38 -0
  197. data/lib/rbs/collection.rb +16 -0
  198. data/lib/rbs/constant.rb +28 -0
  199. data/lib/rbs/definition.rb +415 -0
  200. data/lib/rbs/definition_builder/ancestor_builder.rb +678 -0
  201. data/lib/rbs/definition_builder/method_builder.rb +295 -0
  202. data/lib/rbs/definition_builder.rb +1054 -0
  203. data/lib/rbs/diff.rb +131 -0
  204. data/lib/rbs/environment/class_entry.rb +69 -0
  205. data/lib/rbs/environment/module_entry.rb +66 -0
  206. data/lib/rbs/environment/use_map.rb +77 -0
  207. data/lib/rbs/environment.rb +1028 -0
  208. data/lib/rbs/environment_loader.rb +167 -0
  209. data/lib/rbs/environment_walker.rb +155 -0
  210. data/lib/rbs/errors.rb +634 -0
  211. data/lib/rbs/factory.rb +18 -0
  212. data/lib/rbs/file_finder.rb +28 -0
  213. data/lib/rbs/inline_parser/comment_association.rb +117 -0
  214. data/lib/rbs/inline_parser.rb +568 -0
  215. data/lib/rbs/location_aux.rb +170 -0
  216. data/lib/rbs/locator.rb +247 -0
  217. data/lib/rbs/method_type.rb +145 -0
  218. data/lib/rbs/namespace.rb +154 -0
  219. data/lib/rbs/parser/lex_result.rb +15 -0
  220. data/lib/rbs/parser/token.rb +23 -0
  221. data/lib/rbs/parser_aux.rb +142 -0
  222. data/lib/rbs/prototype/helpers.rb +197 -0
  223. data/lib/rbs/prototype/node_usage.rb +99 -0
  224. data/lib/rbs/prototype/rb.rb +816 -0
  225. data/lib/rbs/prototype/rbi.rb +625 -0
  226. data/lib/rbs/prototype/runtime/helpers.rb +59 -0
  227. data/lib/rbs/prototype/runtime/reflection.rb +19 -0
  228. data/lib/rbs/prototype/runtime/value_object_generator.rb +279 -0
  229. data/lib/rbs/prototype/runtime.rb +680 -0
  230. data/lib/rbs/repository.rb +127 -0
  231. data/lib/rbs/resolver/constant_resolver.rb +219 -0
  232. data/lib/rbs/resolver/type_name_resolver.rb +167 -0
  233. data/lib/rbs/rewriter.rb +70 -0
  234. data/lib/rbs/sorter.rb +198 -0
  235. data/lib/rbs/source.rb +99 -0
  236. data/lib/rbs/substitution.rb +83 -0
  237. data/lib/rbs/subtractor.rb +204 -0
  238. data/lib/rbs/test/errors.rb +80 -0
  239. data/lib/rbs/test/guaranteed.rb +30 -0
  240. data/lib/rbs/test/hook.rb +212 -0
  241. data/lib/rbs/test/observer.rb +19 -0
  242. data/lib/rbs/test/setup.rb +84 -0
  243. data/lib/rbs/test/setup_helper.rb +50 -0
  244. data/lib/rbs/test/tester.rb +167 -0
  245. data/lib/rbs/test/type_check.rb +457 -0
  246. data/lib/rbs/test.rb +112 -0
  247. data/lib/rbs/type_alias_dependency.rb +100 -0
  248. data/lib/rbs/type_alias_regularity.rb +126 -0
  249. data/lib/rbs/type_name.rb +122 -0
  250. data/lib/rbs/types.rb +1604 -0
  251. data/lib/rbs/unit_test/convertibles.rb +177 -0
  252. data/lib/rbs/unit_test/spy.rb +138 -0
  253. data/lib/rbs/unit_test/type_assertions.rb +383 -0
  254. data/lib/rbs/unit_test/with_aliases.rb +145 -0
  255. data/lib/rbs/unit_test.rb +6 -0
  256. data/lib/rbs/validator.rb +186 -0
  257. data/lib/rbs/variance_calculator.rb +189 -0
  258. data/lib/rbs/vendorer.rb +71 -0
  259. data/lib/rbs/version.rb +5 -0
  260. data/lib/rbs/wasm/deserializer.rb +213 -0
  261. data/lib/rbs/wasm/jars/asm-analysis.jar +0 -0
  262. data/lib/rbs/wasm/jars/asm-commons.jar +0 -0
  263. data/lib/rbs/wasm/jars/asm-tree.jar +0 -0
  264. data/lib/rbs/wasm/jars/asm-util.jar +0 -0
  265. data/lib/rbs/wasm/jars/asm.jar +0 -0
  266. data/lib/rbs/wasm/jars/compiler.jar +0 -0
  267. data/lib/rbs/wasm/jars/log.jar +0 -0
  268. data/lib/rbs/wasm/jars/runtime.jar +0 -0
  269. data/lib/rbs/wasm/jars/wasi.jar +0 -0
  270. data/lib/rbs/wasm/jars/wasm.jar +0 -0
  271. data/lib/rbs/wasm/location.rb +61 -0
  272. data/lib/rbs/wasm/parser.rb +137 -0
  273. data/lib/rbs/wasm/rbs_parser.wasm +0 -0
  274. data/lib/rbs/wasm/runtime.rb +217 -0
  275. data/lib/rbs/wasm/serialization_schema.rb +110 -0
  276. data/lib/rbs/writer.rb +424 -0
  277. data/lib/rbs.rb +117 -0
  278. data/lib/rdoc/discover.rb +20 -0
  279. data/lib/rdoc_plugin/parser.rb +163 -0
  280. data/rbs.gemspec +68 -0
  281. data/schema/annotation.json +14 -0
  282. data/schema/comment.json +26 -0
  283. data/schema/decls.json +326 -0
  284. data/schema/function.json +87 -0
  285. data/schema/location.json +56 -0
  286. data/schema/members.json +266 -0
  287. data/schema/methodType.json +50 -0
  288. data/schema/typeParam.json +52 -0
  289. data/schema/types.json +317 -0
  290. data/sig/ancestor_builder.rbs +163 -0
  291. data/sig/ancestor_graph.rbs +60 -0
  292. data/sig/annotate/annotations.rbs +102 -0
  293. data/sig/annotate/formatter.rbs +24 -0
  294. data/sig/annotate/rdoc_annotater.rbs +85 -0
  295. data/sig/annotate/rdoc_source.rbs +32 -0
  296. data/sig/annotation.rbs +27 -0
  297. data/sig/ast/ruby/annotations.rbs +470 -0
  298. data/sig/ast/ruby/comment_block.rbs +127 -0
  299. data/sig/ast/ruby/declarations.rbs +158 -0
  300. data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
  301. data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
  302. data/sig/ast/ruby/members.rbs +198 -0
  303. data/sig/buffer.rbs +108 -0
  304. data/sig/builtin_names.rbs +44 -0
  305. data/sig/cli/colored_io.rbs +15 -0
  306. data/sig/cli/diff.rbs +15 -0
  307. data/sig/cli/validate.rbs +47 -0
  308. data/sig/cli.rbs +89 -0
  309. data/sig/collection/cleaner.rbs +13 -0
  310. data/sig/collection/config/lockfile.rbs +74 -0
  311. data/sig/collection/config/lockfile_generator.rbs +68 -0
  312. data/sig/collection/config.rbs +46 -0
  313. data/sig/collection/installer.rbs +17 -0
  314. data/sig/collection/sources.rbs +214 -0
  315. data/sig/collection.rbs +4 -0
  316. data/sig/comment.rbs +26 -0
  317. data/sig/constant.rbs +21 -0
  318. data/sig/declarations.rbs +274 -0
  319. data/sig/definition.rbs +232 -0
  320. data/sig/definition_builder.rbs +181 -0
  321. data/sig/diff.rbs +28 -0
  322. data/sig/directives.rbs +77 -0
  323. data/sig/environment/class_entry.rbs +50 -0
  324. data/sig/environment/module_entry.rbs +50 -0
  325. data/sig/environment.rbs +286 -0
  326. data/sig/environment_loader.rbs +111 -0
  327. data/sig/environment_walker.rbs +65 -0
  328. data/sig/errors.rbs +408 -0
  329. data/sig/factory.rbs +5 -0
  330. data/sig/file_finder.rbs +28 -0
  331. data/sig/inline_parser/comment_association.rbs +71 -0
  332. data/sig/inline_parser.rbs +126 -0
  333. data/sig/location.rbs +135 -0
  334. data/sig/locator.rbs +56 -0
  335. data/sig/manifest.yaml +5 -0
  336. data/sig/members.rbs +258 -0
  337. data/sig/method_builder.rbs +89 -0
  338. data/sig/method_types.rbs +58 -0
  339. data/sig/namespace.rbs +161 -0
  340. data/sig/parser.rbs +164 -0
  341. data/sig/prototype/helpers.rbs +29 -0
  342. data/sig/prototype/node_usage.rbs +20 -0
  343. data/sig/prototype/rb.rbs +96 -0
  344. data/sig/prototype/rbi.rbs +75 -0
  345. data/sig/prototype/runtime.rbs +182 -0
  346. data/sig/rbs.rbs +21 -0
  347. data/sig/rdoc/rbs.rbs +67 -0
  348. data/sig/repository.rbs +85 -0
  349. data/sig/resolver/constant_resolver.rbs +92 -0
  350. data/sig/resolver/context.rbs +34 -0
  351. data/sig/resolver/type_name_resolver.rbs +61 -0
  352. data/sig/rewriter.rbs +45 -0
  353. data/sig/shims/bundler.rbs +38 -0
  354. data/sig/shims/enumerable.rbs +5 -0
  355. data/sig/shims/rubygems.rbs +19 -0
  356. data/sig/sorter.rbs +41 -0
  357. data/sig/source.rbs +48 -0
  358. data/sig/substitution.rbs +48 -0
  359. data/sig/subtractor.rbs +37 -0
  360. data/sig/test/errors.rbs +52 -0
  361. data/sig/test/guranteed.rbs +9 -0
  362. data/sig/test/type_check.rbs +19 -0
  363. data/sig/test.rbs +82 -0
  364. data/sig/type_alias_dependency.rbs +53 -0
  365. data/sig/type_alias_regularity.rbs +98 -0
  366. data/sig/type_param.rbs +115 -0
  367. data/sig/typename.rbs +89 -0
  368. data/sig/types.rbs +578 -0
  369. data/sig/unit_test/convertibles.rbs +154 -0
  370. data/sig/unit_test/spy.rbs +22 -0
  371. data/sig/unit_test/type_assertions.rbs +211 -0
  372. data/sig/unit_test/with_aliases.rbs +136 -0
  373. data/sig/use_map.rbs +35 -0
  374. data/sig/util.rbs +9 -0
  375. data/sig/validator.rbs +63 -0
  376. data/sig/variance_calculator.rbs +87 -0
  377. data/sig/vendorer.rbs +51 -0
  378. data/sig/version.rbs +3 -0
  379. data/sig/visitor.rbs +47 -0
  380. data/sig/wasm/deserializer.rbs +66 -0
  381. data/sig/wasm/serialization_schema.rbs +13 -0
  382. data/sig/writer.rbs +127 -0
  383. data/src/ast.c +1628 -0
  384. data/src/lexer.c +3217 -0
  385. data/src/lexer.re +155 -0
  386. data/src/lexstate.c +217 -0
  387. data/src/location.c +31 -0
  388. data/src/parser.c +4255 -0
  389. data/src/serialize.c +958 -0
  390. data/src/string.c +41 -0
  391. data/src/util/rbs_allocator.c +162 -0
  392. data/src/util/rbs_assert.c +19 -0
  393. data/src/util/rbs_buffer.c +54 -0
  394. data/src/util/rbs_constant_pool.c +268 -0
  395. data/src/util/rbs_encoding.c +21308 -0
  396. data/src/util/rbs_unescape.c +167 -0
  397. data/stdlib/abbrev/0/abbrev.rbs +66 -0
  398. data/stdlib/abbrev/0/array.rbs +26 -0
  399. data/stdlib/base64/0/base64.rbs +355 -0
  400. data/stdlib/benchmark/0/benchmark.rbs +452 -0
  401. data/stdlib/bigdecimal/0/big_decimal.rbs +1647 -0
  402. data/stdlib/bigdecimal-math/0/big_math.rbs +280 -0
  403. data/stdlib/bigdecimal-math/0/manifest.yaml +2 -0
  404. data/stdlib/cgi/0/core.rbs +911 -0
  405. data/stdlib/cgi/0/manifest.yaml +4 -0
  406. data/stdlib/cgi-escape/0/escape.rbs +171 -0
  407. data/stdlib/coverage/0/coverage.rbs +266 -0
  408. data/stdlib/csv/0/csv.rbs +3776 -0
  409. data/stdlib/csv/0/manifest.yaml +3 -0
  410. data/stdlib/date/0/date.rbs +1598 -0
  411. data/stdlib/date/0/date_time.rbs +617 -0
  412. data/stdlib/date/0/time.rbs +26 -0
  413. data/stdlib/dbm/0/dbm.rbs +421 -0
  414. data/stdlib/delegate/0/delegator.rbs +187 -0
  415. data/stdlib/delegate/0/kernel.rbs +47 -0
  416. data/stdlib/delegate/0/simple_delegator.rbs +96 -0
  417. data/stdlib/did_you_mean/0/did_you_mean.rbs +344 -0
  418. data/stdlib/digest/0/digest.rbs +687 -0
  419. data/stdlib/erb/0/erb.rbs +933 -0
  420. data/stdlib/etc/0/etc.rbs +884 -0
  421. data/stdlib/fileutils/0/fileutils.rbs +1753 -0
  422. data/stdlib/find/0/find.rbs +49 -0
  423. data/stdlib/forwardable/0/forwardable.rbs +271 -0
  424. data/stdlib/io-console/0/io-console.rbs +414 -0
  425. data/stdlib/ipaddr/0/ipaddr.rbs +436 -0
  426. data/stdlib/json/0/json.rbs +1963 -0
  427. data/stdlib/kconv/0/kconv.rbs +166 -0
  428. data/stdlib/logger/0/formatter.rbs +45 -0
  429. data/stdlib/logger/0/log_device.rbs +100 -0
  430. data/stdlib/logger/0/logger.rbs +796 -0
  431. data/stdlib/logger/0/manifest.yaml +2 -0
  432. data/stdlib/logger/0/period.rbs +17 -0
  433. data/stdlib/logger/0/severity.rbs +34 -0
  434. data/stdlib/minitest/0/kernel.rbs +42 -0
  435. data/stdlib/minitest/0/minitest/abstract_reporter.rbs +52 -0
  436. data/stdlib/minitest/0/minitest/assertion.rbs +17 -0
  437. data/stdlib/minitest/0/minitest/assertions.rbs +590 -0
  438. data/stdlib/minitest/0/minitest/backtrace_filter.rbs +23 -0
  439. data/stdlib/minitest/0/minitest/bench_spec.rbs +102 -0
  440. data/stdlib/minitest/0/minitest/benchmark.rbs +259 -0
  441. data/stdlib/minitest/0/minitest/composite_reporter.rbs +25 -0
  442. data/stdlib/minitest/0/minitest/compress.rbs +13 -0
  443. data/stdlib/minitest/0/minitest/error_on_warning.rbs +3 -0
  444. data/stdlib/minitest/0/minitest/expectation.rbs +2 -0
  445. data/stdlib/minitest/0/minitest/expectations.rbs +21 -0
  446. data/stdlib/minitest/0/minitest/guard.rbs +64 -0
  447. data/stdlib/minitest/0/minitest/mock.rbs +64 -0
  448. data/stdlib/minitest/0/minitest/parallel/executor.rbs +46 -0
  449. data/stdlib/minitest/0/minitest/parallel/test/class_methods.rbs +5 -0
  450. data/stdlib/minitest/0/minitest/parallel/test.rbs +3 -0
  451. data/stdlib/minitest/0/minitest/parallel.rbs +2 -0
  452. data/stdlib/minitest/0/minitest/pride_io.rbs +62 -0
  453. data/stdlib/minitest/0/minitest/pride_lol.rbs +19 -0
  454. data/stdlib/minitest/0/minitest/progress_reporter.rbs +11 -0
  455. data/stdlib/minitest/0/minitest/reportable.rbs +53 -0
  456. data/stdlib/minitest/0/minitest/reporter.rbs +5 -0
  457. data/stdlib/minitest/0/minitest/result.rbs +28 -0
  458. data/stdlib/minitest/0/minitest/runnable.rbs +163 -0
  459. data/stdlib/minitest/0/minitest/skip.rbs +6 -0
  460. data/stdlib/minitest/0/minitest/spec/dsl/instance_methods.rbs +48 -0
  461. data/stdlib/minitest/0/minitest/spec/dsl.rbs +129 -0
  462. data/stdlib/minitest/0/minitest/spec.rbs +11 -0
  463. data/stdlib/minitest/0/minitest/statistics_reporter.rbs +81 -0
  464. data/stdlib/minitest/0/minitest/summary_reporter.rbs +18 -0
  465. data/stdlib/minitest/0/minitest/test/lifecycle_hooks.rbs +92 -0
  466. data/stdlib/minitest/0/minitest/test.rbs +69 -0
  467. data/stdlib/minitest/0/minitest/unexpected_error.rbs +12 -0
  468. data/stdlib/minitest/0/minitest/unexpected_warning.rbs +6 -0
  469. data/stdlib/minitest/0/minitest/unit/test_case.rbs +3 -0
  470. data/stdlib/minitest/0/minitest/unit.rbs +4 -0
  471. data/stdlib/minitest/0/minitest.rbs +115 -0
  472. data/stdlib/monitor/0/monitor.rbs +363 -0
  473. data/stdlib/mutex_m/0/mutex_m.rbs +104 -0
  474. data/stdlib/net-http/0/manifest.yaml +3 -0
  475. data/stdlib/net-http/0/net-http.rbs +5580 -0
  476. data/stdlib/net-protocol/0/manifest.yaml +2 -0
  477. data/stdlib/net-protocol/0/net-protocol.rbs +56 -0
  478. data/stdlib/net-smtp/0/manifest.yaml +2 -0
  479. data/stdlib/net-smtp/0/net-smtp.rbs +55 -0
  480. data/stdlib/nkf/0/nkf.rbs +402 -0
  481. data/stdlib/objspace/0/objspace.rbs +470 -0
  482. data/stdlib/observable/0/observable.rbs +217 -0
  483. data/stdlib/open-uri/0/manifest.yaml +4 -0
  484. data/stdlib/open-uri/0/open-uri.rbs +433 -0
  485. data/stdlib/open3/0/open3.rbs +606 -0
  486. data/stdlib/openssl/0/manifest.yaml +3 -0
  487. data/stdlib/openssl/0/openssl.rbs +12231 -0
  488. data/stdlib/optparse/0/optparse.rbs +1734 -0
  489. data/stdlib/pathname/0/pathname.rbs +36 -0
  490. data/stdlib/pp/0/manifest.yaml +2 -0
  491. data/stdlib/pp/0/pp.rbs +301 -0
  492. data/stdlib/prettyprint/0/prettyprint.rbs +383 -0
  493. data/stdlib/pstore/0/pstore.rbs +608 -0
  494. data/stdlib/psych/0/core_ext.rbs +12 -0
  495. data/stdlib/psych/0/dbm.rbs +237 -0
  496. data/stdlib/psych/0/manifest.yaml +3 -0
  497. data/stdlib/psych/0/psych.rbs +455 -0
  498. data/stdlib/psych/0/store.rbs +57 -0
  499. data/stdlib/pty/0/pty.rbs +240 -0
  500. data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
  501. data/stdlib/rdoc/0/code_object.rbs +52 -0
  502. data/stdlib/rdoc/0/comment.rbs +61 -0
  503. data/stdlib/rdoc/0/context.rbs +153 -0
  504. data/stdlib/rdoc/0/markup.rbs +117 -0
  505. data/stdlib/rdoc/0/options.rbs +76 -0
  506. data/stdlib/rdoc/0/parser.rbs +56 -0
  507. data/stdlib/rdoc/0/rdoc.rbs +393 -0
  508. data/stdlib/rdoc/0/ri.rbs +17 -0
  509. data/stdlib/rdoc/0/store.rbs +48 -0
  510. data/stdlib/rdoc/0/top_level.rbs +97 -0
  511. data/stdlib/resolv/0/manifest.yaml +3 -0
  512. data/stdlib/resolv/0/resolv.rbs +1787 -0
  513. data/stdlib/ripper/0/ripper.rbs +1654 -0
  514. data/stdlib/securerandom/0/manifest.yaml +2 -0
  515. data/stdlib/securerandom/0/securerandom.rbs +49 -0
  516. data/stdlib/shellwords/0/shellwords.rbs +229 -0
  517. data/stdlib/singleton/0/singleton.rbs +134 -0
  518. data/stdlib/socket/0/addrinfo.rbs +666 -0
  519. data/stdlib/socket/0/basic_socket.rbs +590 -0
  520. data/stdlib/socket/0/constants.rbs +2295 -0
  521. data/stdlib/socket/0/ip_socket.rbs +94 -0
  522. data/stdlib/socket/0/socket.rbs +4170 -0
  523. data/stdlib/socket/0/socket_error.rbs +5 -0
  524. data/stdlib/socket/0/tcp_server.rbs +192 -0
  525. data/stdlib/socket/0/tcp_socket.rbs +87 -0
  526. data/stdlib/socket/0/udp_socket.rbs +133 -0
  527. data/stdlib/socket/0/unix_server.rbs +169 -0
  528. data/stdlib/socket/0/unix_socket.rbs +172 -0
  529. data/stdlib/stringio/0/stringio.rbs +1681 -0
  530. data/stdlib/strscan/0/string_scanner.rbs +1648 -0
  531. data/stdlib/tempfile/0/tempfile.rbs +483 -0
  532. data/stdlib/time/0/time.rbs +434 -0
  533. data/stdlib/timeout/0/timeout.rbs +137 -0
  534. data/stdlib/tmpdir/0/tmpdir.rbs +69 -0
  535. data/stdlib/tsort/0/cyclic.rbs +8 -0
  536. data/stdlib/tsort/0/interfaces.rbs +20 -0
  537. data/stdlib/tsort/0/tsort.rbs +410 -0
  538. data/stdlib/uri/0/common.rbs +621 -0
  539. data/stdlib/uri/0/file.rbs +118 -0
  540. data/stdlib/uri/0/ftp.rbs +13 -0
  541. data/stdlib/uri/0/generic.rbs +1116 -0
  542. data/stdlib/uri/0/http.rbs +104 -0
  543. data/stdlib/uri/0/https.rbs +14 -0
  544. data/stdlib/uri/0/ldap.rbs +230 -0
  545. data/stdlib/uri/0/ldaps.rbs +14 -0
  546. data/stdlib/uri/0/mailto.rbs +92 -0
  547. data/stdlib/uri/0/rfc2396_parser.rbs +189 -0
  548. data/stdlib/uri/0/rfc3986_parser.rbs +2 -0
  549. data/stdlib/uri/0/ws.rbs +13 -0
  550. data/stdlib/uri/0/wss.rbs +9 -0
  551. data/stdlib/yaml/0/manifest.yaml +2 -0
  552. data/stdlib/yaml/0/yaml.rbs +1 -0
  553. data/stdlib/zlib/0/buf_error.rbs +10 -0
  554. data/stdlib/zlib/0/data_error.rbs +10 -0
  555. data/stdlib/zlib/0/deflate.rbs +211 -0
  556. data/stdlib/zlib/0/error.rbs +20 -0
  557. data/stdlib/zlib/0/gzip_file/crc_error.rbs +12 -0
  558. data/stdlib/zlib/0/gzip_file/error.rbs +23 -0
  559. data/stdlib/zlib/0/gzip_file/length_error.rbs +12 -0
  560. data/stdlib/zlib/0/gzip_file/no_footer.rbs +11 -0
  561. data/stdlib/zlib/0/gzip_file.rbs +156 -0
  562. data/stdlib/zlib/0/gzip_reader.rbs +293 -0
  563. data/stdlib/zlib/0/gzip_writer.rbs +168 -0
  564. data/stdlib/zlib/0/inflate.rbs +180 -0
  565. data/stdlib/zlib/0/mem_error.rbs +10 -0
  566. data/stdlib/zlib/0/need_dict.rbs +13 -0
  567. data/stdlib/zlib/0/stream_end.rbs +11 -0
  568. data/stdlib/zlib/0/stream_error.rbs +11 -0
  569. data/stdlib/zlib/0/version_error.rbs +11 -0
  570. data/stdlib/zlib/0/zlib.rbs +449 -0
  571. data/stdlib/zlib/0/zstream.rbs +201 -0
  572. data/wasm/README.md +59 -0
  573. data/wasm/rbs_wasm.c +411 -0
  574. metadata +660 -0
data/lib/rbs/types.rb ADDED
@@ -0,0 +1,1604 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RBS
4
+ module Types
5
+ module NoFreeVariables
6
+ def free_variables(set = Set.new)
7
+ set
8
+ end
9
+ end
10
+
11
+ module NoSubst
12
+ def sub(s)
13
+ self
14
+ end
15
+ end
16
+
17
+ module NoTypeName
18
+ def map_type_name(&)
19
+ self
20
+ end
21
+ end
22
+
23
+ module EmptyEachType
24
+ def each_type
25
+ if block_given?
26
+ # nop
27
+ else
28
+ enum_for :each_type
29
+ end
30
+ end
31
+
32
+ def map_type(&block)
33
+ if block
34
+ _ = self
35
+ else
36
+ enum_for(:map_type)
37
+ end
38
+ end
39
+ end
40
+
41
+ module Bases
42
+ class Base
43
+ attr_reader :location
44
+
45
+ def initialize(location:)
46
+ @location = location
47
+ end
48
+
49
+ def ==(other)
50
+ other.is_a?(self.class)
51
+ end
52
+
53
+ def hash
54
+ self.class.hash
55
+ end
56
+
57
+ alias eql? ==
58
+
59
+ include NoFreeVariables
60
+ include NoSubst
61
+ include EmptyEachType
62
+ include NoTypeName
63
+
64
+ def to_json(state = nil)
65
+ klass = to_s.to_sym
66
+ { class: klass, location: location }.to_json(state)
67
+ end
68
+
69
+ def to_s(level = 0)
70
+ case self
71
+ when Types::Bases::Bool
72
+ 'bool'
73
+ when Types::Bases::Void
74
+ 'void'
75
+ when Types::Bases::Any
76
+ raise
77
+ when Types::Bases::Nil
78
+ 'nil'
79
+ when Types::Bases::Top
80
+ 'top'
81
+ when Types::Bases::Bottom
82
+ 'bot'
83
+ when Types::Bases::Self
84
+ 'self'
85
+ when Types::Bases::Instance
86
+ 'instance'
87
+ when Types::Bases::Class
88
+ 'class'
89
+ else
90
+ raise "Unexpected base type: #{inspect}"
91
+ end
92
+ end
93
+
94
+ def has_self_type?
95
+ self.is_a?(Types::Bases::Self)
96
+ end
97
+
98
+ def has_classish_type?
99
+ self.is_a?(Bases::Instance) || self.is_a?(Bases::Class)
100
+ end
101
+
102
+ def with_nonreturn_void?
103
+ self.is_a?(Bases::Void)
104
+ end
105
+ end
106
+
107
+ class Bool < Base; end
108
+ class Void < Base; end
109
+ class Any < Base
110
+ def initialize(location:, todo: false)
111
+ super(location: location)
112
+ if todo
113
+ @string = "__todo__"
114
+ end
115
+ end
116
+
117
+ def to_s(level=0)
118
+ @string || "untyped"
119
+ end
120
+ end
121
+ class Nil < Base; end
122
+ class Top < Base; end
123
+ class Bottom < Base; end
124
+ class Self < Base; end
125
+ class Instance < Base
126
+ def sub(s)
127
+ s.apply(self)
128
+ end
129
+ end
130
+ class Class < Base; end
131
+ end
132
+
133
+ class Variable
134
+ attr_reader :name
135
+ attr_reader :location
136
+
137
+ include NoTypeName
138
+
139
+ def initialize(name:, location:)
140
+ @name = name
141
+ @location = location
142
+ end
143
+
144
+ def ==(other)
145
+ other.is_a?(Variable) && other.name == name
146
+ end
147
+
148
+ alias eql? ==
149
+
150
+ def hash
151
+ self.class.hash ^ name.hash
152
+ end
153
+
154
+ def free_variables(set = Set.new)
155
+ set.tap do
156
+ set << name
157
+ end
158
+ end
159
+
160
+ def to_json(state = nil)
161
+ { class: :variable, name: name, location: location }.to_json(state)
162
+ end
163
+
164
+ def sub(s)
165
+ s.apply(self)
166
+ end
167
+
168
+ def self.build(v)
169
+ case v
170
+ when Symbol
171
+ new(name: v, location: nil)
172
+ when Array
173
+ v.map {|x| new(name: x, location: nil) }
174
+ end
175
+ end
176
+
177
+ @@count = 0
178
+ def self.fresh(v = :T)
179
+ @@count = @@count + 1
180
+ new(name: :"#{v}@#{@@count}", location: nil)
181
+ end
182
+
183
+ def to_s(level = 0)
184
+ name.to_s
185
+ end
186
+
187
+ include EmptyEachType
188
+
189
+ def has_self_type?
190
+ false
191
+ end
192
+
193
+ def has_classish_type?
194
+ false
195
+ end
196
+
197
+ def with_nonreturn_void?
198
+ false
199
+ end
200
+ end
201
+
202
+ module Application
203
+ attr_reader :name
204
+ attr_reader :args
205
+
206
+ def ==(other)
207
+ other.is_a?(self.class) && other.name == name && other.args == args
208
+ end
209
+
210
+ alias eql? ==
211
+
212
+ def hash
213
+ name.hash ^ args.hash
214
+ end
215
+
216
+ def free_variables(set = Set.new)
217
+ set.tap do
218
+ args.each do |arg|
219
+ arg.free_variables(set)
220
+ end
221
+ end
222
+ end
223
+
224
+ def to_s(level = 0)
225
+ if args.empty?
226
+ name.to_s
227
+ else
228
+ "#{name}[#{args.join(", ")}]"
229
+ end
230
+ end
231
+
232
+ def each_type(&block)
233
+ if block
234
+ args.each(&block)
235
+ else
236
+ enum_for :each_type
237
+ end
238
+ end
239
+
240
+ def has_self_type?
241
+ each_type.any? {|type| type.has_self_type? }
242
+ end
243
+
244
+ def has_classish_type?
245
+ each_type.any? {|type| type.has_classish_type? }
246
+ end
247
+
248
+ def with_nonreturn_void?
249
+ each_type.any? do |type|
250
+ if type.is_a?(Bases::Void)
251
+ # `void` in immediate generics parameter is allowed
252
+ false
253
+ else
254
+ type.with_nonreturn_void? # steep:ignore DeprecatedReference
255
+ end
256
+ end
257
+ end
258
+ end
259
+
260
+ class ClassSingleton
261
+ attr_reader :location
262
+
263
+ include Application
264
+
265
+ def initialize(name:, location:, args: [])
266
+ @name = name
267
+ @location = location
268
+ @args = args
269
+ end
270
+
271
+ def ==(other)
272
+ other.is_a?(ClassSingleton) && other.name == name && other.args == args
273
+ end
274
+
275
+ alias eql? ==
276
+
277
+ def hash
278
+ self.class.hash ^ name.hash ^ args.hash
279
+ end
280
+
281
+ def sub(s)
282
+ return self if s.empty?
283
+
284
+ self.class.new(name: name,
285
+ args: args.map {|ty| ty.sub(s) },
286
+ location: location)
287
+ end
288
+
289
+ def to_json(state = _ = nil)
290
+ { class: :class_singleton, name: name, args: args, location: location }.to_json(state)
291
+ end
292
+
293
+ def to_s(level = 0)
294
+ if args.empty?
295
+ "singleton(#{name})"
296
+ else
297
+ "singleton(#{name})[#{args.join(", ")}]"
298
+ end
299
+ end
300
+
301
+ def map_type_name(&block)
302
+ ClassSingleton.new(
303
+ name: yield(name, location, self),
304
+ args: args.map {|type| type.map_type_name(&block) },
305
+ location: location
306
+ )
307
+ end
308
+
309
+ def map_type(&block)
310
+ if block
311
+ ClassSingleton.new(
312
+ name: name,
313
+ args: args.map {|type| yield type },
314
+ location: location
315
+ )
316
+ else
317
+ enum_for :map_type
318
+ end
319
+ end
320
+ end
321
+
322
+ class Interface
323
+ attr_reader :location
324
+
325
+ include Application
326
+
327
+ def initialize(name:, args:, location:)
328
+ @name = name
329
+ @args = args
330
+ @location = location
331
+ end
332
+
333
+ def to_json(state = nil)
334
+ { class: :interface, name: name, args: args, location: location }.to_json(state)
335
+ end
336
+
337
+ def sub(s)
338
+ return self if s.empty?
339
+
340
+ self.class.new(name: name,
341
+ args: args.map {|ty| ty.sub(s) },
342
+ location: location)
343
+ end
344
+
345
+ def map_type_name(&block)
346
+ Interface.new(
347
+ name: yield(name, location, self),
348
+ args: args.map {|type| type.map_type_name(&block) },
349
+ location: location
350
+ )
351
+ end
352
+
353
+ def map_type(&block)
354
+ if block
355
+ Interface.new(
356
+ name: name,
357
+ args: args.map {|type| yield type },
358
+ location: location
359
+ )
360
+ else
361
+ enum_for(:map_type)
362
+ end
363
+ end
364
+ end
365
+
366
+ class ClassInstance
367
+ attr_reader :location
368
+
369
+ include Application
370
+
371
+ def initialize(name:, args:, location:)
372
+ @name = name
373
+ @args = args
374
+ @location = location
375
+ end
376
+
377
+ def to_json(state = nil)
378
+ { class: :class_instance, name: name, args: args, location: location }.to_json(state)
379
+ end
380
+
381
+ def sub(s)
382
+ return self if s.empty?
383
+
384
+ self.class.new(name: name,
385
+ args: args.map {|ty| ty.sub(s) },
386
+ location: location)
387
+ end
388
+
389
+ def map_type_name(&block)
390
+ ClassInstance.new(
391
+ name: yield(name, location, self),
392
+ args: args.map {|type| type.map_type_name(&block) },
393
+ location: location
394
+ )
395
+ end
396
+
397
+ def map_type(&block)
398
+ if block
399
+ ClassInstance.new(
400
+ name: name,
401
+ args: args.map {|type| yield type },
402
+ location: location
403
+ )
404
+ else
405
+ enum_for :map_type
406
+ end
407
+ end
408
+ end
409
+
410
+ class Alias
411
+ attr_reader :location
412
+
413
+ include Application
414
+
415
+ def initialize(name:, args:, location:)
416
+ @name = name
417
+ @args = args
418
+ @location = location
419
+ end
420
+
421
+ def to_json(state = nil)
422
+ { class: :alias, name: name, args: args, location: location }.to_json(state)
423
+ end
424
+
425
+ def sub(s)
426
+ return self if s.empty?
427
+
428
+ Alias.new(name: name, args: args.map {|ty| ty.sub(s) }, location: location)
429
+ end
430
+
431
+ def map_type_name(&block)
432
+ Alias.new(
433
+ name: yield(name, location, self),
434
+ args: args.map {|arg| arg.map_type_name(&block) },
435
+ location: location
436
+ )
437
+ end
438
+
439
+ def map_type(&block)
440
+ if block
441
+ Alias.new(
442
+ name: name,
443
+ args: args.map {|type| yield type },
444
+ location: location
445
+ )
446
+ else
447
+ enum_for :map_type
448
+ end
449
+ end
450
+ end
451
+
452
+ class Tuple
453
+ attr_reader :types
454
+ attr_reader :location
455
+
456
+ def initialize(types:, location:)
457
+ @types = types
458
+ @location = location
459
+ end
460
+
461
+ def ==(other)
462
+ other.is_a?(Tuple) && other.types == types
463
+ end
464
+
465
+ alias eql? ==
466
+
467
+ def hash
468
+ self.class.hash ^ types.hash
469
+ end
470
+
471
+ def free_variables(set = Set.new)
472
+ set.tap do
473
+ types.each do |type|
474
+ type.free_variables set
475
+ end
476
+ end
477
+ end
478
+
479
+ def to_json(state = nil)
480
+ { class: :tuple, types: types, location: location }.to_json(state)
481
+ end
482
+
483
+ def sub(s)
484
+ return self if s.empty?
485
+
486
+ self.class.new(types: types.map {|ty| ty.sub(s) },
487
+ location: location)
488
+ end
489
+
490
+ def to_s(level = 0)
491
+ if types.empty?
492
+ "[ ]"
493
+ else
494
+ "[ #{types.join(", ")} ]"
495
+ end
496
+ end
497
+
498
+ def each_type(&block)
499
+ if block
500
+ types.each(&block)
501
+ else
502
+ enum_for :each_type
503
+ end
504
+ end
505
+
506
+ def map_type_name(&block)
507
+ Tuple.new(
508
+ types: types.map {|type| type.map_type_name(&block) },
509
+ location: location
510
+ )
511
+ end
512
+
513
+ def map_type(&block)
514
+ if block
515
+ Tuple.new(
516
+ types: types.map {|type| yield type },
517
+ location: location
518
+ )
519
+ else
520
+ enum_for :map_type
521
+ end
522
+ end
523
+
524
+ def has_self_type?
525
+ each_type.any? {|type| type.has_self_type? }
526
+ end
527
+
528
+ def has_classish_type?
529
+ each_type.any? {|type| type.has_classish_type? }
530
+ end
531
+
532
+ def with_nonreturn_void?
533
+ each_type.any? {|type| type.with_nonreturn_void? } # steep:ignore DeprecatedReference
534
+ end
535
+ end
536
+
537
+ class Record
538
+ attr_reader :all_fields, :fields, :optional_fields
539
+ attr_reader :location
540
+
541
+ def initialize(all_fields: nil, fields: nil, location:)
542
+ case
543
+ when fields && all_fields.nil?
544
+ @all_fields = fields.transform_values { |v| [v, true] }
545
+ @fields = fields
546
+ @optional_fields = {}
547
+ when all_fields && fields.nil?
548
+ @all_fields = all_fields
549
+ @fields = {}
550
+ @optional_fields = {}
551
+ all_fields.each do |(k, (v, required))|
552
+ if required
553
+ @fields[k] = v
554
+ else
555
+ @optional_fields[k] = v
556
+ end
557
+ end
558
+ else
559
+ raise ArgumentError, "only one of `:fields` or `:all_fields` is required"
560
+ end
561
+
562
+ @location = location
563
+ end
564
+
565
+ def ==(other)
566
+ other.is_a?(Record) && other.fields == fields && other.optional_fields == optional_fields
567
+ end
568
+
569
+ alias eql? ==
570
+
571
+ def hash
572
+ self.class.hash ^ all_fields.hash
573
+ end
574
+
575
+ def free_variables(set = Set.new)
576
+ set.tap do
577
+ fields.each_value do |type|
578
+ type.free_variables set
579
+ end
580
+ optional_fields.each_value do |type|
581
+ type.free_variables set
582
+ end
583
+ end
584
+ end
585
+
586
+ def to_json(state = nil)
587
+ { class: :record, fields: fields, optional_fields: optional_fields, location: location }.to_json(state)
588
+ end
589
+
590
+ def sub(s)
591
+ return self if s.empty?
592
+
593
+ self.class.new(
594
+ all_fields: all_fields.transform_values {|ty, required| [ty.sub(s), required] },
595
+ location: location
596
+ )
597
+ end
598
+
599
+ def to_s(level = 0)
600
+ return "{ }" if all_fields.empty?
601
+
602
+ fields = all_fields.map do |key, (type, required)|
603
+ field = if key.is_a?(Symbol) && key.match?(/\A[A-Za-z_][A-Za-z_0-9]*\z/)
604
+ "#{key}: #{type}"
605
+ else
606
+ "#{key.inspect} => #{type}"
607
+ end
608
+
609
+ field = "?#{field}" unless required
610
+ field
611
+ end
612
+ "{ #{fields.join(", ")} }"
613
+ end
614
+
615
+ def each_type(&block)
616
+ if block
617
+ fields.each_value(&block)
618
+ optional_fields.each_value(&block)
619
+ else
620
+ enum_for :each_type
621
+ end
622
+ end
623
+
624
+ def map_type_name(&block)
625
+ Record.new(
626
+ all_fields: all_fields.transform_values {|ty, required| [ty.map_type_name(&block), required] },
627
+ location: location
628
+ )
629
+ end
630
+
631
+ def map_type(&block)
632
+ if block
633
+ Record.new(
634
+ all_fields: all_fields.transform_values {|type, required| [yield(type), required] },
635
+ location: location
636
+ )
637
+ else
638
+ enum_for :map_type
639
+ end
640
+ end
641
+
642
+ def has_self_type?
643
+ each_type.any? {|type| type.has_self_type? }
644
+ end
645
+
646
+ def has_classish_type?
647
+ each_type.any? {|type| type.has_classish_type? }
648
+ end
649
+
650
+ def with_nonreturn_void?
651
+ each_type.any? {|type| type.with_nonreturn_void? } # steep:ignore DeprecatedReference
652
+ end
653
+ end
654
+
655
+ class Optional
656
+ attr_reader :type
657
+ attr_reader :location
658
+
659
+ def initialize(type:, location:)
660
+ @type = type
661
+ @location = location
662
+ end
663
+
664
+ def ==(other)
665
+ other.is_a?(Optional) && other.type == type
666
+ end
667
+
668
+ alias eql? ==
669
+
670
+ def hash
671
+ self.class.hash ^ type.hash
672
+ end
673
+
674
+ def free_variables(set = Set.new)
675
+ type.free_variables(set)
676
+ end
677
+
678
+ def to_json(state = nil)
679
+ { class: :optional, type: type, location: location }.to_json(state)
680
+ end
681
+
682
+ def sub(s)
683
+ return self if s.empty?
684
+
685
+ self.class.new(type: type.sub(s), location: location)
686
+ end
687
+
688
+ def to_s(level = 0)
689
+ case t = type
690
+ when RBS::Types::Literal
691
+ case t.literal
692
+ when Symbol
693
+ return "#{type.to_s(1)} ?"
694
+ end
695
+ when RBS::Types::Proc
696
+ return "(#{type.to_s(1)})?"
697
+ end
698
+
699
+ "#{type.to_s(1)}?"
700
+ end
701
+
702
+ def each_type
703
+ if block_given?
704
+ yield type
705
+ else
706
+ enum_for :each_type
707
+ end
708
+ end
709
+
710
+ def map_type_name(&block)
711
+ Optional.new(
712
+ type: type.map_type_name(&block),
713
+ location: location
714
+ )
715
+ end
716
+
717
+ def map_type(&block)
718
+ if block
719
+ Optional.new(
720
+ type: yield(type),
721
+ location: location
722
+ )
723
+ else
724
+ enum_for :map_type
725
+ end
726
+ end
727
+
728
+ def has_self_type?
729
+ each_type.any? {|type| type.has_self_type? }
730
+ end
731
+
732
+ def has_classish_type?
733
+ each_type.any? {|type| type.has_classish_type? }
734
+ end
735
+
736
+ def with_nonreturn_void?
737
+ each_type.any? {|type| type.with_nonreturn_void? } # steep:ignore DeprecatedReference
738
+ end
739
+ end
740
+
741
+ class Union
742
+ attr_reader :types
743
+ attr_reader :location
744
+
745
+ def initialize(types:, location:)
746
+ @types = types
747
+ @location = location
748
+ end
749
+
750
+ def ==(other)
751
+ other.is_a?(Union) && other.types == types
752
+ end
753
+
754
+ alias eql? ==
755
+
756
+ def hash
757
+ self.class.hash ^ types.hash
758
+ end
759
+
760
+ def free_variables(set = Set.new)
761
+ set.tap do
762
+ types.each do |type|
763
+ type.free_variables set
764
+ end
765
+ end
766
+ end
767
+
768
+ def to_json(state = nil)
769
+ { class: :union, types: types, location: location }.to_json(state)
770
+ end
771
+
772
+ def sub(s)
773
+ return self if s.empty?
774
+
775
+ self.class.new(types: types.map {|ty| ty.sub(s) },
776
+ location: location)
777
+ end
778
+
779
+ def to_s(level = 0)
780
+ strs = types.map do |ty|
781
+ case ty
782
+ when Intersection
783
+ ty.to_s([1, level].max)
784
+ else
785
+ ty.to_s
786
+ end
787
+ end
788
+
789
+ if level > 0
790
+ "(#{strs.join(" | ")})"
791
+ else
792
+ strs.join(" | ")
793
+ end
794
+ end
795
+
796
+ def each_type(&block)
797
+ if block
798
+ types.each(&block)
799
+ else
800
+ enum_for :each_type
801
+ end
802
+ end
803
+
804
+ def map_type(&block)
805
+ if block
806
+ Union.new(types: types.map(&block), location: location)
807
+ else
808
+ enum_for :map_type
809
+ end
810
+ end
811
+
812
+ def map_type_name(&block)
813
+ Union.new(
814
+ types: types.map {|type| type.map_type_name(&block) },
815
+ location: location
816
+ )
817
+ end
818
+
819
+ def has_self_type?
820
+ each_type.any? {|type| type.has_self_type? }
821
+ end
822
+
823
+ def has_classish_type?
824
+ each_type.any? {|type| type.has_classish_type? }
825
+ end
826
+
827
+ def with_nonreturn_void?
828
+ each_type.any? {|type| type.with_nonreturn_void? } # steep:ignore DeprecatedReference
829
+ end
830
+ end
831
+
832
+ class Intersection
833
+ attr_reader :types
834
+ attr_reader :location
835
+
836
+ def initialize(types:, location:)
837
+ @types = types
838
+ @location = location
839
+ end
840
+
841
+ def ==(other)
842
+ other.is_a?(Intersection) && other.types == types
843
+ end
844
+
845
+ alias eql? ==
846
+
847
+ def hash
848
+ self.class.hash ^ types.hash
849
+ end
850
+
851
+ def free_variables(set = Set.new)
852
+ set.tap do
853
+ types.each do |type|
854
+ type.free_variables set
855
+ end
856
+ end
857
+ end
858
+
859
+ def to_json(state = nil)
860
+ { class: :intersection, types: types, location: location }.to_json(state)
861
+ end
862
+
863
+ def sub(s)
864
+ return self if s.empty?
865
+
866
+ self.class.new(types: types.map {|ty| ty.sub(s) },
867
+ location: location)
868
+ end
869
+
870
+ def to_s(level = 0)
871
+ strs = types.map {|ty| ty.to_s(2) }
872
+ if level > 0
873
+ "(#{strs.join(" & ")})"
874
+ else
875
+ strs.join(" & ")
876
+ end
877
+ end
878
+
879
+ def each_type(&block)
880
+ if block
881
+ types.each(&block)
882
+ else
883
+ enum_for :each_type
884
+ end
885
+ end
886
+
887
+ def map_type(&block)
888
+ if block
889
+ Intersection.new(types: types.map(&block), location: location)
890
+ else
891
+ enum_for :map_type
892
+ end
893
+ end
894
+
895
+ def map_type_name(&block)
896
+ Intersection.new(
897
+ types: types.map {|type| type.map_type_name(&block) },
898
+ location: location
899
+ )
900
+ end
901
+
902
+ def has_self_type?
903
+ each_type.any? {|type| type.has_self_type? }
904
+ end
905
+
906
+ def has_classish_type?
907
+ each_type.any? {|type| type.has_classish_type? }
908
+ end
909
+
910
+ def with_nonreturn_void?
911
+ each_type.any? {|type| type.with_nonreturn_void? } # steep:ignore DeprecatedReference
912
+ end
913
+ end
914
+
915
+ class Function
916
+ class Param
917
+ attr_reader :type
918
+ attr_reader :name
919
+ attr_reader :location
920
+
921
+ def initialize(type:, name:, location: nil)
922
+ @type = type
923
+ @name = name
924
+ @location = location
925
+ end
926
+
927
+ def ==(other)
928
+ other.is_a?(Param) && other.type == type && other.name == name
929
+ end
930
+
931
+ alias eql? ==
932
+
933
+ def hash
934
+ self.class.hash ^ type.hash ^ name.hash
935
+ end
936
+
937
+ def map_type(&block)
938
+ if block
939
+ Param.new(name: name, type: yield(type), location: location)
940
+ else
941
+ enum_for :map_type
942
+ end
943
+ end
944
+
945
+ def to_json(state = nil)
946
+ { type: type, name: name }.to_json(state)
947
+ end
948
+
949
+ def to_s
950
+ if name
951
+ if name.match?(/\A[a-zA-Z0-9_]+\z/)
952
+ "#{type} #{name}"
953
+ else
954
+ "#{type} `#{name}`"
955
+ end
956
+ else
957
+ "#{type}"
958
+ end
959
+ end
960
+ end
961
+
962
+ attr_reader :required_positionals
963
+ attr_reader :optional_positionals
964
+ attr_reader :rest_positionals
965
+ attr_reader :trailing_positionals
966
+ attr_reader :required_keywords
967
+ attr_reader :optional_keywords
968
+ attr_reader :rest_keywords
969
+ attr_reader :return_type
970
+
971
+ def initialize(required_positionals:, optional_positionals:, rest_positionals:, trailing_positionals:, required_keywords:, optional_keywords:, rest_keywords:, return_type:)
972
+ @return_type = return_type
973
+ @required_positionals = required_positionals
974
+ @optional_positionals = optional_positionals
975
+ @rest_positionals = rest_positionals
976
+ @trailing_positionals = trailing_positionals
977
+ @required_keywords = required_keywords
978
+ @optional_keywords = optional_keywords
979
+ @rest_keywords = rest_keywords
980
+ end
981
+
982
+ def ==(other)
983
+ other.is_a?(Function) &&
984
+ other.required_positionals == required_positionals &&
985
+ other.optional_positionals == optional_positionals &&
986
+ other.rest_positionals == rest_positionals &&
987
+ other.trailing_positionals == trailing_positionals &&
988
+ other.required_keywords == required_keywords &&
989
+ other.optional_keywords == optional_keywords &&
990
+ other.rest_keywords == rest_keywords &&
991
+ other.return_type == return_type
992
+ end
993
+
994
+ alias eql? ==
995
+
996
+ def hash
997
+ self.class.hash ^
998
+ required_positionals.hash ^
999
+ optional_positionals.hash ^
1000
+ rest_positionals.hash ^
1001
+ trailing_positionals.hash ^
1002
+ required_keywords.hash ^
1003
+ optional_keywords.hash ^
1004
+ rest_keywords.hash ^
1005
+ return_type.hash
1006
+ end
1007
+
1008
+ def free_variables(set = Set.new)
1009
+ set.tap do
1010
+ required_positionals.each do |param|
1011
+ param.type.free_variables(set)
1012
+ end
1013
+ optional_positionals.each do |param|
1014
+ param.type.free_variables(set)
1015
+ end
1016
+ rest_positionals&.yield_self do |param|
1017
+ param.type.free_variables(set)
1018
+ end
1019
+ trailing_positionals.each do |param|
1020
+ param.type.free_variables(set)
1021
+ end
1022
+ required_keywords.each_value do |param|
1023
+ param.type.free_variables(set)
1024
+ end
1025
+ optional_keywords.each_value do |param|
1026
+ param.type.free_variables(set)
1027
+ end
1028
+ rest_keywords&.yield_self do |param|
1029
+ param.type.free_variables(set)
1030
+ end
1031
+
1032
+ return_type.free_variables(set)
1033
+ end
1034
+ end
1035
+
1036
+ def map_type(&block)
1037
+ if block
1038
+ Function.new(
1039
+ required_positionals: amap(required_positionals) {|param| param.map_type(&block) },
1040
+ optional_positionals: amap(optional_positionals) {|param| param.map_type(&block) },
1041
+ rest_positionals: rest_positionals&.yield_self {|param| param.map_type(&block) },
1042
+ trailing_positionals: amap(trailing_positionals) {|param| param.map_type(&block) },
1043
+ required_keywords: hmapv(required_keywords) {|param| param.map_type(&block) },
1044
+ optional_keywords: hmapv(optional_keywords) {|param| param.map_type(&block) },
1045
+ rest_keywords: rest_keywords&.yield_self {|param| param.map_type(&block) },
1046
+ return_type: yield(return_type)
1047
+ )
1048
+ else
1049
+ enum_for :map_type
1050
+ end
1051
+ end
1052
+
1053
+ def amap(array, &block)
1054
+ if array.empty?
1055
+ _ = array
1056
+ else
1057
+ array.map(&block)
1058
+ end
1059
+ end
1060
+
1061
+ def hmapv(hash, &block)
1062
+ if hash.empty?
1063
+ _ = hash
1064
+ else
1065
+ hash.transform_values(&block)
1066
+ end
1067
+ end
1068
+
1069
+ def map_type_name(&block)
1070
+ map_type do |type|
1071
+ type.map_type_name(&block)
1072
+ end
1073
+ end
1074
+
1075
+ def each_type
1076
+ if block_given?
1077
+ required_positionals.each {|param| yield param.type }
1078
+ optional_positionals.each {|param| yield param.type }
1079
+ rest_positionals&.yield_self {|param| yield param.type }
1080
+ trailing_positionals.each {|param| yield param.type }
1081
+ required_keywords.each_value {|param| yield param.type }
1082
+ optional_keywords.each_value {|param| yield param.type }
1083
+ rest_keywords&.yield_self {|param| yield param.type }
1084
+ yield(return_type)
1085
+ else
1086
+ enum_for :each_type
1087
+ end
1088
+ end
1089
+
1090
+ def each_param(&block)
1091
+ if block
1092
+ required_positionals.each(&block)
1093
+ optional_positionals.each(&block)
1094
+ rest_positionals&.yield_self(&block)
1095
+ trailing_positionals.each(&block)
1096
+ required_keywords.each_value(&block)
1097
+ optional_keywords.each_value(&block)
1098
+ rest_keywords&.yield_self(&block)
1099
+ else
1100
+ enum_for :each_param
1101
+ end
1102
+ end
1103
+
1104
+ def to_json(state = nil)
1105
+ {
1106
+ required_positionals: required_positionals,
1107
+ optional_positionals: optional_positionals,
1108
+ rest_positionals: rest_positionals,
1109
+ trailing_positionals: trailing_positionals,
1110
+ required_keywords: required_keywords,
1111
+ optional_keywords: optional_keywords,
1112
+ rest_keywords: rest_keywords,
1113
+ return_type: return_type
1114
+ }.to_json(state)
1115
+ end
1116
+
1117
+ def sub(s)
1118
+ return self if s.empty?
1119
+
1120
+ map_type {|ty| ty.sub(s) }
1121
+ end
1122
+
1123
+ def self.empty(return_type)
1124
+ Function.new(
1125
+ required_positionals: [],
1126
+ optional_positionals: [],
1127
+ rest_positionals: nil,
1128
+ trailing_positionals: [],
1129
+ required_keywords: {},
1130
+ optional_keywords: {},
1131
+ rest_keywords: nil,
1132
+ return_type: return_type
1133
+ )
1134
+ end
1135
+
1136
+ def with_return_type(type)
1137
+ Function.new(
1138
+ required_positionals: required_positionals,
1139
+ optional_positionals: optional_positionals,
1140
+ rest_positionals: rest_positionals,
1141
+ trailing_positionals: trailing_positionals,
1142
+ required_keywords: required_keywords,
1143
+ optional_keywords: optional_keywords,
1144
+ rest_keywords: rest_keywords,
1145
+ return_type: type
1146
+ )
1147
+ end
1148
+
1149
+ def update(required_positionals: self.required_positionals, optional_positionals: self.optional_positionals, rest_positionals: self.rest_positionals, trailing_positionals: self.trailing_positionals,
1150
+ required_keywords: self.required_keywords, optional_keywords: self.optional_keywords, rest_keywords: self.rest_keywords, return_type: self.return_type)
1151
+ Function.new(
1152
+ required_positionals: required_positionals,
1153
+ optional_positionals: optional_positionals,
1154
+ rest_positionals: rest_positionals,
1155
+ trailing_positionals: trailing_positionals,
1156
+ required_keywords: required_keywords,
1157
+ optional_keywords: optional_keywords,
1158
+ rest_keywords: rest_keywords,
1159
+ return_type: return_type
1160
+ )
1161
+ end
1162
+
1163
+ def empty?
1164
+ required_positionals.empty? &&
1165
+ optional_positionals.empty? &&
1166
+ !rest_positionals &&
1167
+ trailing_positionals.empty? &&
1168
+ required_keywords.empty? &&
1169
+ optional_keywords.empty? &&
1170
+ !rest_keywords
1171
+ end
1172
+
1173
+ def param_to_s
1174
+ # @type var params: Array[String]
1175
+ params = []
1176
+
1177
+ params.push(*required_positionals.map(&:to_s))
1178
+ params.push(*optional_positionals.map {|p| "?#{p}"})
1179
+ params.push("*#{rest_positionals}") if rest_positionals
1180
+ params.push(*trailing_positionals.map(&:to_s))
1181
+ params.push(*required_keywords.map {|name, param| "#{name}: #{param}" })
1182
+ params.push(*optional_keywords.map {|name, param| "?#{name}: #{param}" })
1183
+ params.push("**#{rest_keywords}") if rest_keywords
1184
+
1185
+ params.join(", ")
1186
+ end
1187
+
1188
+ def return_to_s
1189
+ return_type.to_s(1)
1190
+ end
1191
+
1192
+ def drop_head
1193
+ case
1194
+ when !required_positionals.empty?
1195
+ [
1196
+ required_positionals[0],
1197
+ update(required_positionals: required_positionals.drop(1))
1198
+ ]
1199
+ when !optional_positionals.empty?
1200
+ [
1201
+ optional_positionals[0],
1202
+ update(optional_positionals: optional_positionals.drop(1))
1203
+ ]
1204
+ else
1205
+ raise "Cannot #drop_head"
1206
+ end
1207
+ end
1208
+
1209
+ def drop_tail
1210
+ case
1211
+ when !trailing_positionals.empty?
1212
+ last = trailing_positionals.last or raise
1213
+ [
1214
+ last,
1215
+ update(trailing_positionals: trailing_positionals.take(trailing_positionals.size - 1))
1216
+ ]
1217
+ else
1218
+ raise "Cannot #drop_tail"
1219
+ end
1220
+ end
1221
+
1222
+ def has_keyword?
1223
+ if !required_keywords.empty? || !optional_keywords.empty? || rest_keywords
1224
+ true
1225
+ else
1226
+ false
1227
+ end
1228
+ end
1229
+
1230
+ def has_self_type?
1231
+ each_type.any? {|type| type.has_self_type? }
1232
+ end
1233
+
1234
+ def has_classish_type?
1235
+ each_type.any? {|type| type.has_classish_type? }
1236
+ end
1237
+
1238
+ def with_nonreturn_void?
1239
+ if each_param.any? {|param| param.type.with_nonreturn_void? } # steep:ignore DeprecatedReference
1240
+ true
1241
+ else
1242
+ if return_type.is_a?(Bases::Void)
1243
+ false
1244
+ else
1245
+ return_type.with_nonreturn_void? # steep:ignore DeprecatedReference
1246
+ end
1247
+ end
1248
+ end
1249
+ end
1250
+
1251
+ class UntypedFunction
1252
+ attr_reader :return_type
1253
+
1254
+ def initialize(return_type:)
1255
+ @return_type = return_type
1256
+ end
1257
+
1258
+ def free_variables(acc = Set.new)
1259
+ return_type.free_variables(acc)
1260
+ end
1261
+
1262
+ def map_type(&block)
1263
+ if block
1264
+ update(return_type: yield(return_type))
1265
+ else
1266
+ enum_for :map_type
1267
+ end
1268
+ end
1269
+
1270
+ def map_type_name(&block)
1271
+ UntypedFunction.new(
1272
+ return_type: return_type.map_type_name(&block)
1273
+ )
1274
+ end
1275
+
1276
+ def each_type(&block)
1277
+ if block
1278
+ yield return_type
1279
+ else
1280
+ enum_for :each_type
1281
+ end
1282
+ end
1283
+
1284
+ def each_param(&block)
1285
+ if block
1286
+ # noop
1287
+ else
1288
+ enum_for :each_param
1289
+ end
1290
+ end
1291
+
1292
+ def to_json(state = nil)
1293
+ {
1294
+ return_type: return_type
1295
+ }.to_json(state)
1296
+ end
1297
+
1298
+ def sub(subst)
1299
+ return self if subst.empty?
1300
+
1301
+ map_type { _1.sub(subst) }
1302
+ end
1303
+
1304
+ def with_return_type(ty)
1305
+ update(return_type: ty)
1306
+ end
1307
+
1308
+ def update(return_type: self.return_type)
1309
+ UntypedFunction.new(return_type: return_type)
1310
+ end
1311
+
1312
+ def empty?
1313
+ true
1314
+ end
1315
+
1316
+ def has_self_type?
1317
+ return_type.has_self_type?
1318
+ end
1319
+
1320
+ def has_classish_type?
1321
+ return_type.has_classish_type?
1322
+ end
1323
+
1324
+ def with_nonreturn_void?
1325
+ false
1326
+ end
1327
+
1328
+ def param_to_s
1329
+ "?"
1330
+ end
1331
+
1332
+ def return_to_s
1333
+ return_type.to_s(1)
1334
+ end
1335
+
1336
+ def ==(other)
1337
+ other.is_a?(UntypedFunction) && other.return_type == return_type
1338
+ end
1339
+
1340
+ alias eql? ==
1341
+
1342
+ def hash
1343
+ self.class.hash ^ return_type.hash
1344
+ end
1345
+
1346
+ end
1347
+
1348
+ class Block
1349
+ attr_reader :type
1350
+ attr_reader :required
1351
+ attr_reader :self_type
1352
+ attr_reader :location
1353
+
1354
+ def initialize(location: nil, type:, required:, self_type: nil)
1355
+ @location = location
1356
+ @type = type
1357
+ @required = required ? true : false
1358
+ @self_type = self_type
1359
+ end
1360
+
1361
+ def ==(other)
1362
+ other.is_a?(Block) &&
1363
+ other.type == type &&
1364
+ other.required == required &&
1365
+ other.self_type == self_type
1366
+ end
1367
+
1368
+ def to_json(state = nil)
1369
+ {
1370
+ type: type,
1371
+ required: required,
1372
+ self_type: self_type
1373
+ }.to_json(state)
1374
+ end
1375
+
1376
+ def sub(s)
1377
+ return self if s.empty?
1378
+
1379
+ self.class.new(
1380
+ type: type.sub(s),
1381
+ required: required,
1382
+ self_type: self_type&.sub(s)
1383
+ )
1384
+ end
1385
+
1386
+ def map_type(&block)
1387
+ Block.new(
1388
+ required: required,
1389
+ type: type.map_type(&block),
1390
+ self_type: self_type ? yield(self_type) : nil
1391
+ )
1392
+ end
1393
+ end
1394
+
1395
+ module SelfTypeBindingHelper
1396
+ module_function
1397
+
1398
+ def self_type_binding_to_s(t)
1399
+ if t
1400
+ "[self: #{t}] "
1401
+ else
1402
+ ""
1403
+ end
1404
+ end
1405
+ end
1406
+
1407
+ class Proc
1408
+ attr_reader :type
1409
+ attr_reader :block
1410
+ attr_reader :self_type
1411
+ attr_reader :location
1412
+
1413
+ def initialize(location:, type:, block:, self_type: nil)
1414
+ @type = type
1415
+ @block = block
1416
+ @location = location
1417
+ @self_type = self_type
1418
+ end
1419
+
1420
+ def ==(other)
1421
+ other.is_a?(Proc) && other.type == type && other.block == block && other.self_type == self_type
1422
+ end
1423
+
1424
+ alias eql? ==
1425
+
1426
+ def hash
1427
+ self.class.hash ^ type.hash ^ block.hash ^ self_type.hash
1428
+ end
1429
+
1430
+ def free_variables(set = Set[])
1431
+ type.free_variables(set)
1432
+ block&.type&.free_variables(set)
1433
+ self_type&.free_variables(set)
1434
+ set
1435
+ end
1436
+
1437
+ def to_json(state = nil)
1438
+ {
1439
+ class: :proc,
1440
+ type: type,
1441
+ block: block,
1442
+ location: location,
1443
+ self_type: self_type
1444
+ }.to_json(state)
1445
+ end
1446
+
1447
+ def sub(s)
1448
+ return self if s.empty?
1449
+
1450
+ self.class.new(
1451
+ type: type.sub(s),
1452
+ block: block&.sub(s),
1453
+ self_type: self_type&.sub(s),
1454
+ location: location
1455
+ )
1456
+ end
1457
+
1458
+ def to_s(level = 0)
1459
+ self_binding = SelfTypeBindingHelper.self_type_binding_to_s(self_type)
1460
+ block_self_binding = SelfTypeBindingHelper.self_type_binding_to_s(block&.self_type)
1461
+
1462
+ case
1463
+ when b = block
1464
+ if b.required
1465
+ "^(#{type.param_to_s}) #{self_binding}{ (#{b.type.param_to_s}) #{block_self_binding}-> #{b.type.return_to_s} } -> #{type.return_to_s}"
1466
+ else
1467
+ "^(#{type.param_to_s}) #{self_binding}?{ (#{b.type.param_to_s}) #{block_self_binding}-> #{b.type.return_to_s} } -> #{type.return_to_s}"
1468
+ end
1469
+ else
1470
+ "^(#{type.param_to_s}) #{self_binding}-> #{type.return_to_s}"
1471
+ end
1472
+ end
1473
+
1474
+ def each_type(&block)
1475
+ if block
1476
+ type.each_type(&block)
1477
+ yield self_type if self_type
1478
+ self.block&.type&.each_type(&block)
1479
+ if self_type = self.block&.self_type
1480
+ yield self_type
1481
+ end
1482
+ else
1483
+ enum_for :each_type
1484
+ end
1485
+ end
1486
+
1487
+ def map_type_name(&block)
1488
+ Proc.new(
1489
+ type: type.map_type_name(&block),
1490
+ block: self.block&.map_type {|type| type.map_type_name(&block) },
1491
+ self_type: self_type&.map_type_name(&block),
1492
+ location: location
1493
+ )
1494
+ end
1495
+
1496
+ def map_type(&block)
1497
+ if block
1498
+ Proc.new(
1499
+ type: type.map_type(&block),
1500
+ block: self.block&.map_type(&block),
1501
+ self_type: self_type ? yield(self_type) : nil,
1502
+ location: location
1503
+ )
1504
+ else
1505
+ enum_for :map_type
1506
+ end
1507
+ end
1508
+
1509
+ def has_self_type?
1510
+ each_type.any? {|type| type.has_self_type? }
1511
+ end
1512
+
1513
+ def has_classish_type?
1514
+ each_type.any? {|type| type.has_classish_type? }
1515
+ end
1516
+
1517
+ def with_nonreturn_void?
1518
+ if type.with_nonreturn_void? || self_type&.with_nonreturn_void? # steep:ignore DeprecatedReference
1519
+ true
1520
+ else
1521
+ if block = block()
1522
+ block.type.with_nonreturn_void? || block.self_type&.with_nonreturn_void? || false # steep:ignore DeprecatedReference
1523
+ else
1524
+ false
1525
+ end
1526
+ end
1527
+ end
1528
+ end
1529
+
1530
+ class Literal
1531
+ attr_reader :literal
1532
+ attr_reader :location
1533
+
1534
+ def initialize(literal:, location:)
1535
+ @literal = literal
1536
+ @location = location
1537
+ end
1538
+
1539
+ def ==(other)
1540
+ other.is_a?(Literal) && other.literal == literal
1541
+ end
1542
+
1543
+ alias eql? ==
1544
+
1545
+ def hash
1546
+ self.class.hash ^ literal.hash
1547
+ end
1548
+
1549
+ include NoFreeVariables
1550
+ include NoSubst
1551
+ include EmptyEachType
1552
+ include NoTypeName
1553
+
1554
+ def to_json(state = nil)
1555
+ { class: :literal, literal: literal.inspect, location: location }.to_json(state)
1556
+ end
1557
+
1558
+ def to_s(level = 0)
1559
+ literal.inspect
1560
+ end
1561
+
1562
+ def has_self_type?
1563
+ false
1564
+ end
1565
+
1566
+ def has_classish_type?
1567
+ false
1568
+ end
1569
+
1570
+ def with_nonreturn_void?
1571
+ false
1572
+ end
1573
+
1574
+ TABLE = {
1575
+ "\\a" => "\a",
1576
+ "\\b" => "\b",
1577
+ "\\e" => "\033",
1578
+ "\\f" => "\f",
1579
+ "\\n" => "\n",
1580
+ "\\r" => "\r",
1581
+ "\\s" => " ",
1582
+ "\\t" => "\t",
1583
+ "\\v" => "\v",
1584
+ "\\\"" => "\"",
1585
+ "\\\'" => "'",
1586
+ "\\\\" => "\\",
1587
+ "\\" => ""
1588
+ }
1589
+
1590
+ def self.unescape_string(string, is_double_quote)
1591
+ if is_double_quote
1592
+ string.gsub!(/\\([0-9]{1,3})/) { ($1 || "").to_i(8).chr }
1593
+ string.gsub!(/\\x([0-9a-f]{1,2})/) { ($1 || "").to_i(16).chr }
1594
+ string.gsub!(/\\u([0-9a-fA-F]{4})/) { ($1 || "").to_i(16).chr(Encoding::UTF_8) }
1595
+ string.gsub!(/\\[abefnrstv"'\\]?/, TABLE)
1596
+ string
1597
+ else
1598
+ string.gsub!(/\\['\\]/, TABLE)
1599
+ string
1600
+ end
1601
+ end
1602
+ end
1603
+ end
1604
+ end