rigortype 0.4.8 → 0.4.9

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 (349) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/docs/handbook/01-getting-started.md +1 -1
  4. data/docs/handbook/04-tuples-and-shapes.md +6 -1
  5. data/docs/handbook/12-lightweight-hkt.md +1 -1
  6. data/docs/handbook/appendix-typescript.md +28 -17
  7. data/docs/manual/02-cli-reference.md +10 -0
  8. data/docs/manual/03-configuration.md +1 -1
  9. data/docs/manual/04-diagnostics.md +1 -1
  10. data/docs/manual/10-mcp-server.md +122 -10
  11. data/docs/manual/plugins/rigor-activerecord.md +7 -0
  12. data/lib/rigor/analysis/check_rules/always_raises.rb +95 -0
  13. data/lib/rigor/analysis/check_rules/always_truthy_condition_collector.rb +32 -2
  14. data/lib/rigor/analysis/check_rules/argument_type.rb +802 -0
  15. data/lib/rigor/analysis/check_rules/call_facts.rb +2 -2
  16. data/lib/rigor/analysis/check_rules/dead_assignment_collector.rb +30 -1
  17. data/lib/rigor/analysis/check_rules/declaration_sourced_guard.rb +4 -5
  18. data/lib/rigor/analysis/check_rules/duplicate_hash_key_collector.rb +34 -0
  19. data/lib/rigor/analysis/check_rules/ivar_write_collector.rb +131 -4
  20. data/lib/rigor/analysis/check_rules/nil_receiver.rb +195 -0
  21. data/lib/rigor/analysis/check_rules/override_param_narrowed.rb +111 -0
  22. data/lib/rigor/analysis/check_rules/override_return_widened.rb +88 -0
  23. data/lib/rigor/analysis/check_rules/override_support.rb +246 -0
  24. data/lib/rigor/analysis/check_rules/override_visibility.rb +135 -0
  25. data/lib/rigor/analysis/check_rules/published_constant_guard.rb +75 -31
  26. data/lib/rigor/analysis/check_rules/raise_non_exception.rb +198 -0
  27. data/lib/rigor/analysis/check_rules/receiver_predicates.rb +576 -0
  28. data/lib/rigor/analysis/check_rules/return_in_ensure_collector.rb +52 -4
  29. data/lib/rigor/analysis/check_rules/return_type.rb +225 -0
  30. data/lib/rigor/analysis/check_rules/rigor_testing.rb +119 -0
  31. data/lib/rigor/analysis/check_rules/rule_ids.rb +7 -7
  32. data/lib/rigor/analysis/check_rules/rule_walk.rb +4 -3
  33. data/lib/rigor/analysis/check_rules/self_closedness_scanner.rb +2 -0
  34. data/lib/rigor/analysis/check_rules/self_undefined_method.rb +165 -0
  35. data/lib/rigor/analysis/check_rules/shadowed_rescue_collector.rb +34 -0
  36. data/lib/rigor/analysis/check_rules/source_arity.rb +2 -2
  37. data/lib/rigor/analysis/check_rules/special_global_write.rb +256 -0
  38. data/lib/rigor/analysis/check_rules/suppression.rb +275 -0
  39. data/lib/rigor/analysis/check_rules/undefined_method.rb +882 -0
  40. data/lib/rigor/analysis/check_rules/unreachable_branch.rb +97 -0
  41. data/lib/rigor/analysis/check_rules/unreachable_clause_collector.rb +42 -0
  42. data/lib/rigor/analysis/check_rules/unresolved_toplevel.rb +140 -0
  43. data/lib/rigor/analysis/check_rules/visibility_mismatch.rb +252 -0
  44. data/lib/rigor/analysis/check_rules/void_value_use_collector.rb +27 -0
  45. data/lib/rigor/analysis/check_rules/wrong_arity.rb +303 -0
  46. data/lib/rigor/analysis/check_rules.rb +66 -4931
  47. data/lib/rigor/analysis/dependency_recorder.rb +1 -1
  48. data/lib/rigor/analysis/dependency_source_inference/builder.rb +2 -4
  49. data/lib/rigor/analysis/dependency_source_inference/gem_resolver.rb +1 -2
  50. data/lib/rigor/analysis/dependency_source_inference/walker.rb +15 -15
  51. data/lib/rigor/analysis/incremental_session.rb +4 -4
  52. data/lib/rigor/analysis/path_expansion.rb +1 -1
  53. data/lib/rigor/analysis/plugin_fact_fingerprint.rb +5 -5
  54. data/lib/rigor/analysis/reachability/graph.rb +2 -3
  55. data/lib/rigor/analysis/reachability/plugin_roots.rb +2 -2
  56. data/lib/rigor/analysis/reachability/scan.rb +2 -2
  57. data/lib/rigor/analysis/rule_catalog.rb +2 -1
  58. data/lib/rigor/analysis/run_cache_key.rb +9 -8
  59. data/lib/rigor/analysis/runner/buffer_pool_dispatcher.rb +2 -2
  60. data/lib/rigor/analysis/runner/dependency_rows.rb +206 -0
  61. data/lib/rigor/analysis/runner/diagnostic_aggregator.rb +24 -22
  62. data/lib/rigor/analysis/runner/effect_cache_entries.rb +69 -0
  63. data/lib/rigor/analysis/runner/pool_coordinator.rb +6 -8
  64. data/lib/rigor/analysis/runner/project_pre_passes.rb +3 -5
  65. data/lib/rigor/analysis/runner/scope_seed.rb +144 -0
  66. data/lib/rigor/analysis/runner.rb +49 -296
  67. data/lib/rigor/analysis/template_unit_collector.rb +1 -1
  68. data/lib/rigor/analysis/template_units.rb +10 -10
  69. data/lib/rigor/analysis/worker_session.rb +7 -7
  70. data/lib/rigor/bleeding_edge.rb +3 -2
  71. data/lib/rigor/builtins/hkt_builtins.rb +17 -17
  72. data/lib/rigor/builtins/imported_refinements.rb +8 -16
  73. data/lib/rigor/builtins/regex_refinement.rb +3 -3
  74. data/lib/rigor/builtins/static_return_refinements.rb +143 -19
  75. data/lib/rigor/cache/incremental_snapshot.rb +21 -8
  76. data/lib/rigor/cache/rbs_descriptor.rb +18 -1
  77. data/lib/rigor/cli/coverage_renderer.rb +15 -1
  78. data/lib/rigor/cli/coverage_report.rb +19 -1
  79. data/lib/rigor/cli/diagnostic_formats.rb +3 -2
  80. data/lib/rigor/cli/docs_command.rb +5 -5
  81. data/lib/rigor/cli/effects_command.rb +7 -6
  82. data/lib/rigor/cli/fused_protection_report.rb +7 -7
  83. data/lib/rigor/cli/lsp_command.rb +1 -1
  84. data/lib/rigor/cli/mcp_command.rb +5 -2
  85. data/lib/rigor/cli/options.rb +4 -0
  86. data/lib/rigor/cli/plugins_command.rb +1 -1
  87. data/lib/rigor/cli/sig_gen_command.rb +1 -1
  88. data/lib/rigor/cli/skill_command.rb +5 -4
  89. data/lib/rigor/cli/triage_renderer.rb +3 -2
  90. data/lib/rigor/cli/unused_command.rb +4 -4
  91. data/lib/rigor/cli.rb +14 -0
  92. data/lib/rigor/configuration/coercion.rb +418 -0
  93. data/lib/rigor/configuration/defaults.rb +248 -0
  94. data/lib/rigor/configuration/dependencies.rb +1 -1
  95. data/lib/rigor/configuration/loader.rb +354 -0
  96. data/lib/rigor/configuration/severity_profile.rb +4 -4
  97. data/lib/rigor/configuration.rb +51 -860
  98. data/lib/rigor/effects/attribution.rb +1 -1
  99. data/lib/rigor/effects/effect_table.rb +1 -1
  100. data/lib/rigor/effects/identity.rb +3 -3
  101. data/lib/rigor/effects/local_ownership.rb +2 -2
  102. data/lib/rigor/effects/snapshot.rb +1 -1
  103. data/lib/rigor/effects/summary.rb +5 -4
  104. data/lib/rigor/environment/member_consistency.rb +10 -0
  105. data/lib/rigor/environment/rbs_loader.rb +19 -22
  106. data/lib/rigor/environment/reflection.rb +1 -1
  107. data/lib/rigor/environment/unreadable_signature.rb +21 -0
  108. data/lib/rigor/environment.rb +8 -8
  109. data/lib/rigor/flow_contribution/merger.rb +1 -0
  110. data/lib/rigor/hashing/xxh3.rb +1 -1
  111. data/lib/rigor/inference/acceptance.rb +23 -2
  112. data/lib/rigor/inference/alias_mutation_floor/site_collector.rb +5 -0
  113. data/lib/rigor/inference/alias_mutation_floor.rb +0 -5
  114. data/lib/rigor/inference/anonymous_meta_class.rb +2 -2
  115. data/lib/rigor/inference/block_call_timing.rb +6 -0
  116. data/lib/rigor/inference/budget_trace.rb +3 -2
  117. data/lib/rigor/inference/builtins/date_catalog.rb +3 -3
  118. data/lib/rigor/inference/builtins/method_catalog.rb +3 -3
  119. data/lib/rigor/inference/builtins/time_catalog.rb +3 -3
  120. data/lib/rigor/inference/call_ladder/literal_send.rb +98 -0
  121. data/lib/rigor/inference/call_ladder/overriding_def.rb +98 -0
  122. data/lib/rigor/inference/call_ladder/project_singleton.rb +362 -0
  123. data/lib/rigor/inference/call_ladder/refined.rb +212 -0
  124. data/lib/rigor/inference/call_ladder/top_level_def.rb +222 -0
  125. data/lib/rigor/inference/call_ladder/user_method.rb +247 -0
  126. data/lib/rigor/inference/call_ladder.rb +219 -0
  127. data/lib/rigor/inference/callee_write_census.rb +2 -2
  128. data/lib/rigor/inference/captured_locals.rb +2 -2
  129. data/lib/rigor/inference/clause_widening.rb +63 -1
  130. data/lib/rigor/inference/declaration_walk/context.rb +12 -12
  131. data/lib/rigor/inference/declaration_walk/rules.rb +750 -0
  132. data/lib/rigor/inference/declaration_walk/traversal.rb +9 -8
  133. data/lib/rigor/inference/declaration_walk.rb +4 -3
  134. data/lib/rigor/inference/def_node_resolver.rb +2 -2
  135. data/lib/rigor/inference/def_return_typer.rb +14 -6
  136. data/lib/rigor/inference/deferred_mutation.rb +120 -0
  137. data/lib/rigor/inference/define_method_block_self.rb +1 -1
  138. data/lib/rigor/inference/definer_resolution.rb +4 -4
  139. data/lib/rigor/inference/error_info.rb +8 -8
  140. data/lib/rigor/inference/expression_typer/composites.rb +348 -0
  141. data/lib/rigor/inference/expression_typer/per_element_assemblers.rb +233 -0
  142. data/lib/rigor/inference/expression_typer/writes.rb +218 -0
  143. data/lib/rigor/inference/expression_typer.rb +275 -1825
  144. data/lib/rigor/inference/external_ancestor_resolution.rb +2 -2
  145. data/lib/rigor/inference/fallback.rb +1 -0
  146. data/lib/rigor/inference/for_yield_slots.rb +126 -0
  147. data/lib/rigor/inference/genuine_send.rb +92 -0
  148. data/lib/rigor/inference/global_write_census.rb +2 -2
  149. data/lib/rigor/inference/hkt_body.rb +2 -0
  150. data/lib/rigor/inference/in_effect_refinements/walk.rb +2 -2
  151. data/lib/rigor/inference/index_write_widening.rb +4 -4
  152. data/lib/rigor/inference/indexed_narrowing.rb +1 -1
  153. data/lib/rigor/inference/intervening_ivar_reset.rb +46 -9
  154. data/lib/rigor/inference/ivar_writer_census.rb +1 -1
  155. data/lib/rigor/inference/loop_store_sites.rb +239 -0
  156. data/lib/rigor/inference/macro_block_self_type.rb +4 -3
  157. data/lib/rigor/inference/method_dispatcher/block_folding.rb +3 -2
  158. data/lib/rigor/inference/method_dispatcher/call_context.rb +84 -14
  159. data/lib/rigor/inference/method_dispatcher/composite_receiver.rb +144 -0
  160. data/lib/rigor/inference/method_dispatcher/constant_folding.rb +7 -5
  161. data/lib/rigor/inference/method_dispatcher/declared_constructor.rb +1 -1
  162. data/lib/rigor/inference/method_dispatcher/dependency_source.rb +90 -0
  163. data/lib/rigor/inference/method_dispatcher/discovered_method.rb +78 -0
  164. data/lib/rigor/inference/method_dispatcher/file_folding.rb +2 -2
  165. data/lib/rigor/inference/method_dispatcher/hkt_builtin_return.rb +40 -0
  166. data/lib/rigor/inference/method_dispatcher/iterator_dispatch.rb +1 -6
  167. data/lib/rigor/inference/method_dispatcher/literal_string_folding.rb +4 -2
  168. data/lib/rigor/inference/method_dispatcher/match_data_folding.rb +1 -1
  169. data/lib/rigor/inference/method_dispatcher/meta_introspection.rb +506 -0
  170. data/lib/rigor/inference/method_dispatcher/overload_selector.rb +2 -0
  171. data/lib/rigor/inference/method_dispatcher/plugin_contribution.rb +134 -0
  172. data/lib/rigor/inference/method_dispatcher/project_patched.rb +134 -0
  173. data/lib/rigor/inference/method_dispatcher/rbs_dispatch.rb +125 -43
  174. data/lib/rigor/inference/method_dispatcher/reduce_folding.rb +3 -4
  175. data/lib/rigor/inference/method_dispatcher/regexp_folding.rb +1 -1
  176. data/lib/rigor/inference/method_dispatcher/set_folding.rb +1 -1
  177. data/lib/rigor/inference/method_dispatcher/shape_dispatch.rb +19 -6
  178. data/lib/rigor/inference/method_dispatcher/singleton_folding.rb +3 -3
  179. data/lib/rigor/inference/method_dispatcher/singleton_mixin_dispatch.rb +7 -4
  180. data/lib/rigor/inference/method_dispatcher/static_refinement.rb +106 -0
  181. data/lib/rigor/inference/method_dispatcher/synthesized_stub.rb +41 -0
  182. data/lib/rigor/inference/method_dispatcher/synthetic_method_dispatch.rb +133 -0
  183. data/lib/rigor/inference/method_dispatcher/universal_object_dispatch.rb +2 -1
  184. data/lib/rigor/inference/method_dispatcher/user_class_fallback.rb +216 -0
  185. data/lib/rigor/inference/method_dispatcher.rb +175 -1361
  186. data/lib/rigor/inference/method_parameter_binder.rb +18 -18
  187. data/lib/rigor/inference/module_function_state.rb +5 -4
  188. data/lib/rigor/inference/mutation_widening.rb +20 -7
  189. data/lib/rigor/inference/narrowing/case_literals.rb +58 -0
  190. data/lib/rigor/inference/narrowing/class_dispatch.rb +302 -0
  191. data/lib/rigor/inference/narrowing/complements.rb +322 -0
  192. data/lib/rigor/inference/narrowing/presence_predicates.rb +205 -0
  193. data/lib/rigor/inference/narrowing/regex_match.rb +499 -0
  194. data/lib/rigor/inference/narrowing.rb +86 -1269
  195. data/lib/rigor/inference/object_mixins.rb +2 -2
  196. data/lib/rigor/inference/opaque_mutation.rb +214 -0
  197. data/lib/rigor/inference/optimistic_origin.rb +52 -14
  198. data/lib/rigor/inference/parameter_inference_collector.rb +1 -1
  199. data/lib/rigor/inference/pre_eval_constants.rb +11 -9
  200. data/lib/rigor/inference/precision_scanner.rb +27 -2
  201. data/lib/rigor/inference/project_patched_methods.rb +3 -3
  202. data/lib/rigor/inference/range_constant.rb +3 -3
  203. data/lib/rigor/inference/rbs_type_translator.rb +2 -2
  204. data/lib/rigor/inference/refine_self.rb +8 -7
  205. data/lib/rigor/inference/refined_dispatch.rb +2 -2
  206. data/lib/rigor/inference/return_barrier.rb +24 -9
  207. data/lib/rigor/inference/scope_indexer/alias_def_nodes.rb +311 -0
  208. data/lib/rigor/inference/scope_indexer/census_scope.rb +47 -0
  209. data/lib/rigor/inference/scope_indexer/certainty.rb +2 -2
  210. data/lib/rigor/inference/scope_indexer/class_cvar_census.rb +282 -0
  211. data/lib/rigor/inference/scope_indexer/class_cvars_collector.rb +12 -5
  212. data/lib/rigor/inference/scope_indexer/class_declarations.rb +228 -0
  213. data/lib/rigor/inference/scope_indexer/class_ivar_index.rb +2028 -0
  214. data/lib/rigor/inference/scope_indexer/constant_ivar_value.rb +4 -3
  215. data/lib/rigor/inference/scope_indexer/constant_tables.rb +844 -0
  216. data/lib/rigor/inference/scope_indexer/cvar_hierarchy.rb +159 -0
  217. data/lib/rigor/inference/scope_indexer/declaration_artifacts.rb +219 -0
  218. data/lib/rigor/inference/scope_indexer/declaration_signature.rb +212 -0
  219. data/lib/rigor/inference/scope_indexer/def_nestings_collector.rb +2 -2
  220. data/lib/rigor/inference/scope_indexer/factory_call_resolver.rb +53 -0
  221. data/lib/rigor/inference/scope_indexer/literal_receiver_mutations.rb +266 -0
  222. data/lib/rigor/inference/scope_indexer/member_layouts_collector.rb +8 -7
  223. data/lib/rigor/inference/scope_indexer/mixin_accumulator.rb +1 -1
  224. data/lib/rigor/inference/scope_indexer/mixin_effects.rb +470 -0
  225. data/lib/rigor/inference/scope_indexer/mixin_tables.rb +388 -0
  226. data/lib/rigor/inference/scope_indexer/mutated_carrier_widening.rb +163 -0
  227. data/lib/rigor/inference/scope_indexer/mutated_element_census.rb +211 -0
  228. data/lib/rigor/inference/scope_indexer/node_propagation.rb +520 -0
  229. data/lib/rigor/inference/scope_indexer/program_globals.rb +154 -0
  230. data/lib/rigor/inference/scope_indexer/published_constant_cvars.rb +146 -0
  231. data/lib/rigor/inference/scope_indexer/published_constant_ivars.rb +181 -0
  232. data/lib/rigor/inference/scope_indexer/shared_walk_tables.rb +823 -0
  233. data/lib/rigor/inference/scope_indexer/singleton_class_sources.rb +85 -0
  234. data/lib/rigor/inference/scope_indexer/superclasses_collector.rb +5 -5
  235. data/lib/rigor/inference/scope_indexer.rb +2657 -9558
  236. data/lib/rigor/inference/self_call_ivar_writes.rb +22 -3
  237. data/lib/rigor/inference/set_mutation.rb +2 -2
  238. data/lib/rigor/inference/singleton_hook_definers.rb +185 -0
  239. data/lib/rigor/inference/statement_evaluator/def_arguments_and_assertions.rb +365 -0
  240. data/lib/rigor/inference/statement_evaluator/pattern_bindings.rb +581 -0
  241. data/lib/rigor/inference/statement_evaluator.rb +201 -1008
  242. data/lib/rigor/inference/synthetic_method_scanner.rb +0 -3
  243. data/lib/rigor/language_server/completion_provider.rb +8 -8
  244. data/lib/rigor/language_server/diagnostic_publisher.rb +6 -7
  245. data/lib/rigor/language_server/document_symbol_provider.rb +4 -6
  246. data/lib/rigor/language_server/folding_range_provider.rb +3 -3
  247. data/lib/rigor/language_server/hover_provider.rb +2 -2
  248. data/lib/rigor/language_server/loop.rb +2 -2
  249. data/lib/rigor/language_server/server.rb +3 -2
  250. data/lib/rigor/language_server/signature_help_provider.rb +7 -9
  251. data/lib/rigor/lens/document.rb +10 -1
  252. data/lib/rigor/lens/file_reader.rb +2 -1
  253. data/lib/rigor/mcp/loop.rb +48 -6
  254. data/lib/rigor/mcp/server.rb +248 -23
  255. data/lib/rigor/mcp/skill_catalog.rb +157 -0
  256. data/lib/rigor/plugin/base.rb +22 -4
  257. data/lib/rigor/plugin/effect_attribution.rb +1 -1
  258. data/lib/rigor/plugin/inflector.rb +2 -2
  259. data/lib/rigor/plugin/io_boundary.rb +1 -1
  260. data/lib/rigor/plugin/loader.rb +4 -4
  261. data/lib/rigor/plugin/macro/heredoc_template.rb +4 -3
  262. data/lib/rigor/plugin/optimistic_return.rb +20 -0
  263. data/lib/rigor/plugin/registry.rb +2 -2
  264. data/lib/rigor/plugin/template_unit.rb +4 -2
  265. data/lib/rigor/plugin/trust_policy.rb +2 -1
  266. data/lib/rigor/plugin.rb +1 -1
  267. data/lib/rigor/protection/mutator.rb +8 -9
  268. data/lib/rigor/rbs_extended/reporter.rb +2 -2
  269. data/lib/rigor/rbs_extended.rb +2 -2
  270. data/lib/rigor/reflection/constant_ancestors.rb +1 -1
  271. data/lib/rigor/reflection/project_method.rb +2 -2
  272. data/lib/rigor/reflection.rb +4 -4
  273. data/lib/rigor/scope/discovery_index.rb +15 -10
  274. data/lib/rigor/scope/resolution_chain.rb +29 -6
  275. data/lib/rigor/scope.rb +89 -32
  276. data/lib/rigor/sig_gen/generator.rb +5 -4
  277. data/lib/rigor/sig_gen/renderer.rb +3 -3
  278. data/lib/rigor/sig_gen/writer.rb +8 -6
  279. data/lib/rigor/source/parameter_envelope.rb +1 -1
  280. data/lib/rigor/triage/catalogue.rb +4 -4
  281. data/lib/rigor/type/combinator.rb +2 -2
  282. data/lib/rigor/type/data_instance.rb +2 -2
  283. data/lib/rigor/type/struct_instance.rb +3 -3
  284. data/lib/rigor/type_node/generic.rb +2 -1
  285. data/lib/rigor/type_of_memo.rb +2 -1
  286. data/lib/rigor/typing_state.rb +3 -2
  287. data/lib/rigor/version.rb +1 -1
  288. data/plugins/rigor-actioncable/lib/rigor/plugin/actioncable/analyzer.rb +2 -2
  289. data/plugins/rigor-actioncable/lib/rigor/plugin/actioncable/channel_discoverer.rb +1 -1
  290. data/plugins/rigor-actionmailer/lib/rigor/plugin/actionmailer/mailer_discoverer.rb +4 -4
  291. data/plugins/rigor-actionmailer/lib/rigor/plugin/actionmailer.rb +1 -1
  292. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/controller_discoverer.rb +4 -3
  293. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/effects.rb +7 -5
  294. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/erb_compiler.rb +4 -2
  295. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/render_locals.rb +1 -1
  296. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/view_assigns.rb +3 -2
  297. data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack.rb +7 -7
  298. data/plugins/rigor-activejob/lib/rigor/plugin/activejob/job_discoverer.rb +1 -1
  299. data/plugins/rigor-activejob/lib/rigor/plugin/activejob.rb +2 -2
  300. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/model_discoverer.rb +9 -8
  301. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/model_index.rb +3 -2
  302. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/schema_parser.rb +15 -7
  303. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/schema_table.rb +10 -3
  304. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/structure_sql_parser.rb +12 -1
  305. data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord.rb +20 -5
  306. data/plugins/rigor-activestorage/lib/rigor/plugin/activestorage/attachment_discoverer.rb +1 -1
  307. data/plugins/rigor-activestorage/lib/rigor/plugin/activestorage.rb +3 -2
  308. data/plugins/rigor-activesupport-core-ext/lib/rigor/plugin/activesupport_core_ext/effects.rb +1 -1
  309. data/plugins/rigor-activesupport-core-ext/lib/rigor/plugin/activesupport_core_ext.rb +8 -7
  310. data/plugins/rigor-dry-schema/lib/rigor/plugin/dry_schema.rb +1 -1
  311. data/plugins/rigor-dry-types/lib/rigor/plugin/dry_types/alias_scanner.rb +1 -1
  312. data/plugins/rigor-dry-types/lib/rigor/plugin/dry_types.rb +6 -7
  313. data/plugins/rigor-factorybot/lib/rigor/plugin/factorybot/factory_discoverer.rb +3 -2
  314. data/plugins/rigor-graphql/lib/rigor/plugin/graphql/type_scanner.rb +4 -3
  315. data/plugins/rigor-hanami/lib/rigor/plugin/hanami.rb +4 -2
  316. data/plugins/rigor-minitest/lib/rigor/plugin/minitest.rb +1 -1
  317. data/plugins/rigor-pundit/lib/rigor/plugin/pundit.rb +1 -1
  318. data/plugins/rigor-rails-i18n/lib/rigor/plugin/rails_i18n/analyzer.rb +5 -3
  319. data/plugins/rigor-rails-i18n/lib/rigor/plugin/rails_i18n.rb +1 -1
  320. data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/devise_routes.rb +4 -5
  321. data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/doorkeeper_routes.rb +2 -2
  322. data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/helper_discoverer.rb +5 -4
  323. data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/helper_table.rb +3 -2
  324. data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/routes_parser.rb +30 -31
  325. data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes.rb +13 -15
  326. data/plugins/rigor-rbnacl/lib/rigor/plugin/rbnacl.rb +1 -1
  327. data/plugins/rigor-rspec/lib/rigor/plugin/rspec/let_scope_index.rb +4 -3
  328. data/plugins/rigor-rspec/lib/rigor/plugin/rspec/matcher_analyzer.rb +16 -13
  329. data/plugins/rigor-rspec/lib/rigor/plugin/rspec/scope_walker.rb +3 -2
  330. data/plugins/rigor-shoulda-matchers/lib/rigor/plugin/shoulda_matchers/analyzer.rb +6 -6
  331. data/plugins/rigor-sidekiq/lib/rigor/plugin/sidekiq/analyzer.rb +3 -3
  332. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/assertion_recognizer.rb +2 -2
  333. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/catalog.rb +3 -2
  334. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/catalog_walker.rb +6 -5
  335. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/sig_parser.rb +2 -2
  336. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/sigil_detector.rb +4 -5
  337. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/type_translator.rb +1 -1
  338. data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet.rb +3 -4
  339. data/sig/rigor/analysis/check_rules/suppression.rbs +9 -0
  340. data/sig/rigor/analysis/dependency_recorder.rbs +9 -0
  341. data/sig/rigor/inference.rbs +275 -11
  342. data/sig/rigor/plugin/base.rbs +14 -5
  343. data/sig/rigor/plugin/optimistic_return.rbs +16 -0
  344. data/sig/rigor/scope.rbs +7 -1
  345. data/sig/rigor/source.rbs +4 -0
  346. data/skills/rigor-mcp-setup/SKILL.md +20 -6
  347. data/skills/rigor-plugin-review/SKILL.md +3 -3
  348. data/skills/rigor-type-oracle/references/01-oracle-commands.md +1 -1
  349. metadata +90 -3
@@ -0,0 +1,134 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "prism"
4
+ require_relative "../../type"
5
+ require_relative "synthetic_method_dispatch"
6
+ # `Scope::ResolutionChain` is left to the load order, as `declared_constructor.rb` and `rbs_dispatch.rb` leave it:
7
+ # `scope.rb` requires the typer, which requires the dispatcher, and the chain does not load ahead of `scope.rb`.
8
+
9
+ module Rigor
10
+ module Inference
11
+ module MethodDispatcher
12
+ # The project-patched tier (ADR-17): a method a `pre_eval:` file patches onto a class answers from the
13
+ # `ProjectPatchedMethods` registry the environment carries. `MethodDispatcher.resolve_site` asks it twice, for
14
+ # the receiver's own class below the synthetic-method tier and, with `through_ancestors: true`, for the
15
+ # receiver's ancestors below the discovered-method tier. It records the origin of each answer, so both are
16
+ # calls there and members of no tier array.
17
+ #
18
+ # An alias whose old name no patch binds re-enters `MethodDispatcher.resolve` ({#project_patched_alias_target}),
19
+ # the module's one call back into the dispatcher. {#explicit_non_self_receiver?} is a second entry: the
20
+ # user-class fallback asks it too.
21
+ module ProjectPatched
22
+ module_function
23
+
24
+ # ADR-17 slice 2 — project-side patched-method tier. Slice 3a uses the registry's
25
+ # heuristic-extracted `return_type` (populated via the same
26
+ # `Analysis::DependencySourceInference::ReturnTypeHeuristic` the ADR-10 walker uses): a
27
+ # `def to_url; "hello"; end` patched onto `String` now resolves `s.to_url` to
28
+ # `Dynamic[Nominal[String]]` instead of the pre-3a `Dynamic[Top]`. Falls back to
29
+ # `Dynamic[Top]` when the heuristic declined (non-literal tail expression).
30
+ #
31
+ # `through_ancestors:` (issue #1708), with a scope, searches the receiver's ancestors as well, through
32
+ # {ProjectPatchedMethods#lookup_through_ancestors}, stopping at a nearer project-source `def`. A private or
33
+ # protected patch Ruby would not let the call reach ({ProjectPatchedMethods#callable?}) answers nothing, so
34
+ # `1.kp` on `module Kernel; private def kp` reads as the undefined call it is.
35
+ def try_dispatch(context, through_ancestors: false) # rubocop:disable Metrics/AbcSize
36
+ receiver_type = context.receiver
37
+ method_name = context.method_name
38
+ arg_types = context.args
39
+ block_type = context.block_type
40
+ environment = context.environment
41
+ call_node = context.call_node
42
+ scope = context.scope
43
+ return nil if environment.nil?
44
+
45
+ registry = environment.project_patched_methods
46
+ return nil if registry.nil? || registry.empty?
47
+
48
+ class_name = SyntheticMethodDispatch.synthetic_method_class_name(receiver_type)
49
+ return nil if class_name.nil?
50
+
51
+ kind = receiver_type.is_a?(Type::Singleton) ? :singleton : :instance
52
+ entry = project_patched_entry(registry, class_name, method_name, kind, environment,
53
+ scope: scope, through_ancestors: through_ancestors)
54
+ return nil if entry.nil?
55
+
56
+ verdict = registry.callable?(entry, explicit: explicit_non_self_receiver?(call_node),
57
+ self_type: scope ? scope.self_type : :unknown,
58
+ rbs_loader: environment.rbs_loader)
59
+ return nil if verdict == false
60
+ return Type::Combinator.untyped if verdict.nil?
61
+ return Type::Combinator.dynamic(entry.return_type) if entry.return_type
62
+
63
+ aliased = project_patched_alias_target(entry, receiver_type, arg_types, block_type, environment)
64
+ aliased ? Type::Combinator.dynamic(aliased) : Type::Combinator.untyped
65
+ end
66
+
67
+ def project_patched_entry(registry, class_name, method_name, kind, environment, scope:, through_ancestors:)
68
+ return registry.lookup(class_name: class_name, method_name: method_name, kind: kind) unless through_ancestors
69
+
70
+ registry.lookup_through_ancestors(
71
+ class_name: class_name, method_name: method_name, kind: kind, rbs_loader: environment.rbs_loader,
72
+ source_defines: ->(owner, side) { project_source_defines?(scope, owner, method_name, side) }
73
+ )
74
+ end
75
+
76
+ # Issue #1708 — does the project's own source define `method_name` on `owner` (`side` as the ancestor walk
77
+ # reaches it), or on a module the project prepends to or includes into it? Ruby runs that `def` ahead of a
78
+ # patch on a farther ancestor: `class Integer; def nn = "s"` beats `class Object; def nn = nil` in a
79
+ # `pre_eval:` file. The owner's level of its {Scope::ResolutionChain} (its prepends, itself, its includes
80
+ # and their own mixins, or a class object's singleton and its extends) holds those definers; whether one
81
+ # of them defines the name does not depend on their order, so the chain is searched without settling it.
82
+ def project_source_defines?(scope, owner, method_name, side)
83
+ return false unless scope.known_user_class?(owner)
84
+
85
+ chain = Scope::ResolutionChain.for(scope, owner, side, :methods)
86
+ own_level_end = chain.level_starts[1] || chain.entries.size
87
+ found = chain.search(scope, 0, own_level_end) do |entry|
88
+ !entry.external? && source_def?(scope, entry.name, method_name, entry.side)
89
+ end
90
+ !found.nil?
91
+ end
92
+
93
+ def source_def?(scope, owner, method_name, side)
94
+ if side == :singleton
95
+ scope.discovered_method?(owner, method_name, :singleton) ||
96
+ !scope.singleton_def_for(owner, method_name).nil?
97
+ else
98
+ scope.discovered_method?(owner, method_name, :instance) || !scope.user_def_for(owner, method_name).nil?
99
+ end
100
+ end
101
+
102
+ # Issue #1702 — an alias in a `pre_eval:` patch whose old name no earlier patch binding defines
103
+ # (`alias old_plus +` on Integer, or `alias_method :orig_succ, :succ` ahead of the patch's own `def succ`)
104
+ # names the method the class had before the patch, so it answers what that method answers for the same
105
+ # arguments, behind the `Dynamic` every patched method carries. The re-entry skips this tier: a later patch
106
+ # `def` of the old name is not the body the alias copied, and the skip is also what ends an alias cycle. It
107
+ # carries no call node or scope, so it answers a type and records nothing at the call site.
108
+ def project_patched_alias_target(entry, receiver_type, arg_types, block_type, environment)
109
+ return nil if entry.alias_of.nil?
110
+
111
+ MethodDispatcher.resolve(
112
+ receiver_type: receiver_type, method_name: entry.alias_of, arg_types: arg_types,
113
+ block_type: block_type, environment: environment, skip_project_patched: true
114
+ )
115
+ end
116
+
117
+ # True when the call node carries an explicit receiver that is not the literal `self`.
118
+ # Such a call cannot legally dispatch to a private method, so the user-class fallback must
119
+ # skip private signatures rather than return a confidently-wrong type. Returns false for
120
+ # implicit-self calls and `self.`-receiver calls (both may legally reach a private method
121
+ # in modern Ruby), and false when no `call_node` is supplied (internal dispatcher callers).
122
+ def explicit_non_self_receiver?(call_node)
123
+ return false if call_node.nil?
124
+ return false unless call_node.respond_to?(:receiver)
125
+
126
+ receiver = call_node.receiver
127
+ return false if receiver.nil?
128
+
129
+ !receiver.is_a?(Prism::SelfNode)
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
@@ -204,7 +204,7 @@ module Rigor
204
204
  # that the block's return type references to it (Slice 6 phase C sub-phase 2).
205
205
  #
206
206
  # `self_type_override`, when set, is the substitution for `Bases::Self` in the method's return type.
207
- # `MethodDispatcher#try_user_class_fallback` uses it to preserve the ORIGINAL receiver as the
207
+ # `UserClassFallback.try_dispatch` uses it to preserve the ORIGINAL receiver as the
208
208
  # substitute for `self` even though the dispatch is routed through `Nominal[Object]` — so that
209
209
  # `Bundler::URI::Generic.dup` (which resolves through the `Object` fallback because
210
210
  # `Bundler::URI::Generic` lacks RBS) returns `Bundler::URI::Generic` per `Kernel#dup: () -> self`
@@ -266,7 +266,7 @@ module Rigor
266
266
  # This deliberately does NOT differentiate "no overload had a block" from "the block is untyped";
267
267
  # the binder treats both the same way (every parameter defaults to `Dynamic[Top]`).
268
268
  # @return positional block parameter types.
269
- def block_param_types(context)
269
+ def block_param_types(context, signature: false)
270
270
  environment = context.environment
271
271
  return [] if environment.nil?
272
272
  return [] unless environment.rbs_loader
@@ -277,10 +277,26 @@ module Rigor
277
277
  args: context.args,
278
278
  environment: environment,
279
279
  scope: context.scope,
280
- call_node: context.call_node
280
+ call_node: context.call_node,
281
+ signature: signature
281
282
  )
282
283
  end
283
284
 
285
+ # Issue #3265 — a block's declared positional parameters by kind, each translated: the `required`, `optional`
286
+ # and `trailing` lists, the `rest` element type (nil when the block declares no rest), and whether it declares a
287
+ # keyword (`keywords`). {#block_param_types} answers `required + optional` alone, which a block literal binds by
288
+ # position; a `for` index binds the values the block receives as one array, keywords included as a Hash.
289
+ BlockSignature = Data.define(:required, :optional, :rest, :trailing, :keywords) do
290
+ # Whether the block always receives exactly the required positionals.
291
+ def fixed_arity? = optional.empty? && rest.nil? && trailing.empty?
292
+ end
293
+
294
+ # The {BlockSignature} the probe {#block_param_types} reads, or nil when it has none.
295
+ def block_signature(context)
296
+ answer = block_param_types(context, signature: true)
297
+ answer.is_a?(BlockSignature) ? answer : nil
298
+ end
299
+
284
300
  # The RBS declaration a `def method_name` on `class_name` (`kind` side) binds its parameters from
285
301
  # (`MethodParameterBinder`): the class's own, or nil.
286
302
  #
@@ -377,17 +393,62 @@ module Rigor
377
393
  end
378
394
  end
379
395
 
396
+ # Issue #3320 — on a literal key read, each `HashShape` / `Tuple` member is first offered to
397
+ # {ShapeDispatch}, which is what answers that member when it is the lone receiver. Without it every shape
398
+ # member projected to `Hash[K, V]` / `Array[E]` in {#dispatch_one}, so
399
+ # `({ a: 1, b: "s" } | { a: 2, b: :t })[:a]` answered every value of every key. A member the shape tier
400
+ # declines, and every other member, keeps its `dispatch_one` answer, so the result is the lone answers
401
+ # joined and no member is dispatched twice.
380
402
  def dispatch_union(receiver, method_name, args, environment, block_type, self_type_override = nil, # rubocop:disable Metrics/ParameterLists
381
403
  public_only: false, scope: nil, call_node: nil)
404
+ shape_read = shape_key_read?(method_name, args)
382
405
  results = receiver.members.map do |member|
383
- dispatch_one(member, method_name, args, environment, block_type, self_type_override,
384
- public_only: public_only, scope: scope, call_node: call_node)
406
+ (shape_read && shape_member_read(member, method_name, args, block_type)) ||
407
+ dispatch_one(member, method_name, args, environment, block_type, self_type_override,
408
+ public_only: public_only, scope: scope, call_node: call_node)
385
409
  end
386
410
  return nil if results.any?(&:nil?)
387
411
 
388
412
  Type::Combinator.union(*results)
389
413
  end
390
414
 
415
+ # The key positions — every argument of `dig`, the first of `[]` / `fetch` — are each a value-pinned
416
+ # `Constant` or a union of them. A computed key (`Symbol`) keeps the projection's answer: a lone shape
417
+ # answers it with every value plus `nil`, which would widen today's answer for the union.
418
+ def shape_key_read?(method_name, args)
419
+ case method_name
420
+ when :dig then !args.empty? && args.all? { |arg| literal_key?(arg) }
421
+ when :[], :fetch then !args.empty? && literal_key?(args.first)
422
+ when :first, :last then true
423
+ else false
424
+ end
425
+ end
426
+
427
+ def literal_key?(arg)
428
+ case arg
429
+ when Type::Constant then true
430
+ when Type::Union then arg.members.all?(Type::Constant)
431
+ else false
432
+ end
433
+ end
434
+
435
+ # `first` / `last` (with or without a count) are element reads on a Tuple; on a HashShape they are not key
436
+ # reads and keep the projection. The block goes to the shape tier as the lone receiver passes it, so a
437
+ # block-form call defers there (ADR-78 WD1) and the member keeps its `dispatch_one` answer.
438
+ def shape_member_read(member, method_name, args, block_type)
439
+ unless member.is_a?(Type::Tuple) || (member.is_a?(Type::HashShape) && hash_key_read?(method_name))
440
+ return nil
441
+ end
442
+
443
+ ShapeDispatch.try_dispatch(
444
+ CallContext.build(receiver: member, method_name: method_name, args: args, block_type: block_type)
445
+ )
446
+ end
447
+
448
+ def hash_key_read?(method_name)
449
+ method_name != :first && method_name != :last
450
+ end
451
+
391
452
  def dispatch_one(receiver, method_name, args, environment, block_type, self_type_override = nil, # rubocop:disable Metrics/ParameterLists
392
453
  public_only: false, scope: nil, call_node: nil)
393
454
  # Issue #1794 — a sequence's inherited Enumerable surface reads its Rigor-private element argument, with
@@ -596,8 +657,8 @@ module Rigor
596
657
 
597
658
  # An open shape's unseen keys may hold any value (rbs-erasure.md § *Open shapes with extra-value
598
659
  # bounds*), so its projection carries a `Dynamic[top]` arm on both sides. Without it every read the
599
- # shape tier does not answer — a `Union` receiver, a non-literal key — took the known values for a
600
- # key outside them: `h = { a: 1 }; h.default = 0 if flag; h[:b] == 1` folded always-truthy.
660
+ # shape tier does not answer — a non-literal key, a `Union` member it defers on — took the known values
661
+ # for a key outside them: `h = { a: 1 }; h.default = 0 if flag; h[:b] == 1` folded always-truthy.
601
662
  def hash_shape_type_args(shape)
602
663
  return [] if shape.pairs.empty?
603
664
 
@@ -768,7 +829,7 @@ module Rigor
768
829
  # working code". Two things narrow it here. The ancestry is core / stdlib, whose RBS is the
769
830
  # method set every negative rule already trusts for a direct receiver of it. And the negative
770
831
  # rules do not reach these receivers anyway: `undefined_method_diagnostic` and
771
- # `arity_envelope_for` gate on `Reflection.rbs_class_known?` of the RECEIVER, which a
832
+ # `WrongArity.arity_envelope_for` gate on `Reflection.rbs_class_known?` of the RECEIVER, which a
772
833
  # Ruby-source subclass never is. So the risk this arm carries is not a new firing but a
773
834
  # WRONG PRECISE TYPE propagating one hop — which is what the declines below are about.
774
835
  #
@@ -1527,9 +1588,6 @@ module Rigor
1527
1588
  record_optimistic_nil_free(method_definition, method_type, scope, call_node)
1528
1589
  end
1529
1590
 
1530
- # The two method-level type-parameter binding positions, layered in precedence order over the
1531
- # receiver-derived `type_vars`: the block return type first, then the argument positions (which
1532
- # never displace an existing key). See {#compose_arg_type_vars} for the argument envelope.
1533
1591
  # Issue #521 — more than one candidate means a `Dynamic[Top]` argument made the overloads
1534
1592
  # indistinguishable; pinning the first answered a wrong precise type the runtime can contradict
1535
1593
  # (`[true] * n` read as String). The join is the candidates' return union wrapped in `Dynamic`,
@@ -1571,6 +1629,10 @@ module Rigor
1571
1629
  Type::Combinator.dynamic(Type::Combinator.union(*distinct))
1572
1630
  end
1573
1631
 
1632
+ # The two method-level type-parameter binding positions, layered in precedence order over the
1633
+ # receiver-derived `type_vars`: the block return type first, then the argument positions (which
1634
+ # never displace an existing key). See {#compose_arg_type_vars} for the argument envelope.
1635
+ #
1574
1636
  # `positional` is `args` less a keyword hash the overload takes as its keywords (#1727). The block-return
1575
1637
  # rule reads every argument, the keyword hash included: a keyword parameter naming the block's variable
1576
1638
  # (`[T] (?default: T) { () -> T } -> T`) is an argument reaching it. The positional binding reads only the
@@ -2131,7 +2193,7 @@ module Rigor
2131
2193
  #
2132
2194
  # 1. `scope` && `call_node` present, the same evidence surface {#record_void_recovery} reads.
2133
2195
  # DIAGNOSED, not assumed: that fixture's `p(1)` reaches here through
2134
- # `MethodDispatcher#try_user_class_fallback`, which dispatches with `scope: nil, call_node:
2196
+ # `UserClassFallback.try_dispatch`, which dispatches with `scope: nil, call_node:
2135
2197
  # nil` — so the presence gate alone already declines every call routed through the Object /
2136
2198
  # Kernel ancestor fallback, the path a class with no RBS of its own always takes.
2137
2199
  # 2. The explicit redefinition probe, in the shape `KernelDispatch#user_redefined?` established.
@@ -2214,11 +2276,6 @@ module Rigor
2214
2276
  end
2215
2277
  end
2216
2278
 
2217
- # The block's type less the falsey values the declared return spells beside the variable: its
2218
- # truthy fragment for `nil | false`, its non-nil fragment for `nil` alone. A `Dynamic` block type
2219
- # passes through unchanged, so an untyped block still binds `Dynamic[top]`. A block that answers
2220
- # only the stripped values binds `bot`, so `filter_map { nil }` is `Array[bot]`: an Array that
2221
- # holds no element.
2222
2279
  # Whether the receiver class's Ruby source defines the dispatched method, the probe
2223
2280
  # {#arg_binding_permitted?} also reads. Without a scope there is no discovery to consult.
2224
2281
  def project_redefined?(scope, call_site)
@@ -2230,6 +2287,11 @@ module Rigor
2230
2287
  scope.discovered_method?(class_name, method_name, kind)
2231
2288
  end
2232
2289
 
2290
+ # The block's type less the falsey values the declared return spells beside the variable: its
2291
+ # truthy fragment for `nil | false`, its non-nil fragment for `nil` alone. A `Dynamic` block type
2292
+ # passes through unchanged, so an untyped block still binds `Dynamic[top]`. A block that answers
2293
+ # only the stripped values binds `bot`, so `filter_map { nil }` is `Array[bot]`: an Array that
2294
+ # holds no element.
2233
2295
  def strip_falsey_arms(block_type, arms)
2234
2296
  return block_type if arms.empty?
2235
2297
  return Narrowing.narrow_truthy(block_type) if arms.include?(:false) # rubocop:disable Lint/BooleanSymbol
@@ -2239,13 +2301,16 @@ module Rigor
2239
2301
 
2240
2302
  # ----- block parameter probe (Phase C sub-phase 1) -----
2241
2303
 
2242
- def probe_block_param_types(receiver:, method_name:, args:, environment:, scope: nil, call_node: nil)
2304
+ # `signature:` answers the whole {BlockSignature} instead of the positional list (issue #3265); a probe with
2305
+ # no information answers `[]` either way.
2306
+ def probe_block_param_types(receiver:, method_name:, args:, environment:, scope: nil, call_node: nil,
2307
+ signature: false)
2243
2308
  args ||= []
2244
2309
  case receiver
2245
2310
  when Type::Union
2246
- probe_block_param_types_union(receiver, method_name, args, environment, scope, call_node)
2311
+ probe_block_param_types_union(receiver, method_name, args, environment, scope, call_node, signature)
2247
2312
  else
2248
- probe_block_param_types_one(receiver, method_name, args, environment, scope, call_node)
2313
+ probe_block_param_types_one(receiver, method_name, args, environment, scope, call_node, signature)
2249
2314
  end
2250
2315
  end
2251
2316
 
@@ -2253,9 +2318,9 @@ module Rigor
2253
2318
  # member resolves the same arity and types (otherwise the call sites would have to thread
2254
2319
  # per-member binders, which the slice does not support yet). Mismatches degrade to the empty
2255
2320
  # array so the binder defaults all params to Dynamic[Top].
2256
- def probe_block_param_types_union(receiver, method_name, args, environment, scope, call_node)
2321
+ def probe_block_param_types_union(receiver, method_name, args, environment, scope, call_node, signature)
2257
2322
  results = receiver.members.map do |member|
2258
- probe_block_param_types_one(member, method_name, args, environment, scope, call_node)
2323
+ probe_block_param_types_one(member, method_name, args, environment, scope, call_node, signature)
2259
2324
  end
2260
2325
  return [] if results.empty?
2261
2326
  return [] unless results.all? { |r| r == results.first }
@@ -2263,7 +2328,7 @@ module Rigor
2263
2328
  results.first
2264
2329
  end
2265
2330
 
2266
- def probe_block_param_types_one(receiver, method_name, args, environment, scope, call_node)
2331
+ def probe_block_param_types_one(receiver, method_name, args, environment, scope, call_node, signature)
2267
2332
  receiver = ArithmeticSequenceElements.element_receiver(receiver, method_name, environment, block: true) ||
2268
2333
  receiver
2269
2334
  descriptor = receiver_descriptor(receiver)
@@ -2284,8 +2349,11 @@ module Rigor
2284
2349
  class_name: class_name, kind: kind, args: args, type_vars: type_vars, environment: environment,
2285
2350
  receiver: receiver, receiver_args: receiver_args, method_name: method_name,
2286
2351
  keywords_last: ArgumentNodes.keyword_hash_last?(call_node, args),
2287
- positional_splat: splat_indices(call_node, args), scope: scope, call_node: call_node
2352
+ positional_splat: splat_indices(call_node, args), scope: scope, call_node: call_node,
2353
+ signature: signature
2288
2354
  )
2355
+ return params if signature
2356
+
2289
2357
  ClassKeyedBlockParams.rebind(method_definition, method_name, args, params)
2290
2358
  rescue StandardError
2291
2359
  []
@@ -2305,7 +2373,7 @@ module Rigor
2305
2373
  def extract_block_param_types(method_definition, class_name:, kind:, args:, type_vars:,
2306
2374
  environment: nil, receiver: nil, receiver_args: [],
2307
2375
  method_name: nil, keywords_last: false, positional_splat: nil,
2308
- scope: nil, call_node: nil)
2376
+ scope: nil, call_node: nil, signature: false)
2309
2377
  # rubocop:enable Metrics/ParameterLists
2310
2378
  instance_type = Type::Combinator.nominal_of(class_name)
2311
2379
  self_type = block_self_type(kind, class_name, instance_type, receiver)
@@ -2325,14 +2393,14 @@ module Rigor
2325
2393
  selector_self = self_type.is_a?(Type::Dynamic) ? self_type.static_facet : self_type
2326
2394
  if keywords_last
2327
2395
  return agreed_keyword_block_params(method_definition, args, self_type, selector_self, instance_type,
2328
- type_vars, environment, positional_splat)
2396
+ type_vars, environment, positional_splat, signature: signature)
2329
2397
  end
2330
2398
 
2331
2399
  # A splat (#1801) leaves the positional count open, so every overload some count reaches must agree.
2332
2400
  if positional_splat || FacetDistribution.faceted?(args)
2333
2401
  matches = facet_matches(method_definition, args, selector_self, instance_type, type_vars, true,
2334
2402
  environment, false, positional_splat)
2335
- return agreed_block_params(matches, self_type, instance_type, type_vars, environment)
2403
+ return agreed_block_params(matches, self_type, instance_type, type_vars, environment, signature:)
2336
2404
  end
2337
2405
 
2338
2406
  method_type = OverloadSelector.select(
@@ -2353,7 +2421,7 @@ module Rigor
2353
2421
  type_vars = compose_singleton_arg_type_vars(method_type, type_vars, args, environment,
2354
2422
  scope: scope, call_node: call_node,
2355
2423
  call_site: [class_name, method_name, kind])
2356
- block_params_of(method_type, self_type, instance_type, type_vars, environment) || []
2424
+ block_params_of(method_type, self_type, instance_type, type_vars, environment, signature: signature) || []
2357
2425
  end
2358
2426
 
2359
2427
  # Issue #2828 — the block-parameter twin of {#compose_arg_type_vars}, for the `singleton(T)` shape alone
@@ -2398,18 +2466,20 @@ module Rigor
2398
2466
  end
2399
2467
 
2400
2468
  # The block parameters every overload in `matches` declares alike, or no information (`[]`).
2401
- def agreed_block_params(matches, self_type, instance_type, type_vars, environment)
2469
+ def agreed_block_params(matches, self_type, instance_type, type_vars, environment, signature: false)
2402
2470
  answers = matches.uniq.map do |method_type|
2403
- block_params_of(method_type, self_type, instance_type, type_vars, environment)
2471
+ block_params_of(method_type, self_type, instance_type, type_vars, environment, signature: signature)
2404
2472
  end
2405
2473
  answers.uniq.size == 1 && answers.first ? answers.first : []
2406
2474
  end
2407
2475
 
2408
- def block_params_of(method_type, self_type, instance_type, type_vars, environment)
2476
+ def block_params_of(method_type, self_type, instance_type, type_vars, environment, signature: false)
2409
2477
  block = method_type.respond_to?(:block) ? method_type.block : nil
2410
2478
  return nil unless block
2411
2479
 
2412
- translate_block_positional_params(
2480
+ translate = signature ? :translate_block_signature : :translate_block_positional_params
2481
+ send(
2482
+ translate,
2413
2483
  block,
2414
2484
  self_type: self_type,
2415
2485
  instance_type: instance_type,
@@ -2439,7 +2509,7 @@ module Rigor
2439
2509
 
2440
2510
  # rubocop:disable Metrics/ParameterLists
2441
2511
  def agreed_keyword_block_params(method_definition, args, self_type, selector_self, instance_type, type_vars,
2442
- environment, splats)
2512
+ environment, splats, signature: false)
2443
2513
  # rubocop:enable Metrics/ParameterLists
2444
2514
  distributions = keyword_distributions(method_definition, args, selector_self, instance_type, type_vars,
2445
2515
  environment, splats)
@@ -2455,7 +2525,7 @@ module Rigor
2455
2525
 
2456
2526
  candidates.concat(matches)
2457
2527
  end
2458
- agreed_block_params(candidates, self_type, instance_type, type_vars, environment)
2528
+ agreed_block_params(candidates, self_type, instance_type, type_vars, environment, signature: signature)
2459
2529
  end
2460
2530
 
2461
2531
  # One distribution's genuine matches. A faceted positional argument (a `Dynamic` with sealed facet members) is
@@ -2500,16 +2570,28 @@ module Rigor
2500
2570
  fun = block.type
2501
2571
  return [] unless fun.respond_to?(:required_positionals)
2502
2572
 
2503
- params = fun.required_positionals + fun.optional_positionals
2504
- params.map do |param|
2505
- RbsTypeTranslator.translate(
2506
- param.type,
2507
- self_type: self_type,
2508
- instance_type: instance_type,
2509
- type_vars: type_vars,
2510
- alias_expander: alias_expander
2511
- )
2573
+ translate = lambda do |param|
2574
+ RbsTypeTranslator.translate(param.type, self_type:, instance_type:, type_vars:, alias_expander:)
2575
+ end
2576
+ (fun.required_positionals + fun.optional_positionals).map(&translate)
2577
+ end
2578
+
2579
+ # Issue #3265 — the block's whole positional list, for a caller that binds by how many values the block
2580
+ # receives (`for a, *s in e`), which the required-and-optional list above cannot tell.
2581
+ def translate_block_signature(block, self_type:, instance_type:, type_vars:, alias_expander: nil)
2582
+ fun = block.type
2583
+ return [] unless fun.respond_to?(:required_positionals)
2584
+
2585
+ translate = lambda do |param|
2586
+ RbsTypeTranslator.translate(param.type, self_type:, instance_type:, type_vars:, alias_expander:)
2512
2587
  end
2588
+ BlockSignature.new(
2589
+ required: fun.required_positionals.map(&translate),
2590
+ optional: fun.optional_positionals.map(&translate),
2591
+ rest: fun.rest_positionals && translate.call(fun.rest_positionals),
2592
+ trailing: fun.trailing_positionals.map(&translate),
2593
+ keywords: !(fun.required_keywords.empty? && fun.optional_keywords.empty? && fun.rest_keywords.nil?)
2594
+ )
2513
2595
  end
2514
2596
  end
2515
2597
  end
@@ -34,8 +34,8 @@ module Rigor
34
34
  #
35
35
  # `widen_value_pinned` (ADR-55/56) collapses `Constant`/`IntegerRange` operands to their nominal base
36
36
  # before dispatch so the result is the operator's nominal return (`Integer`) rather than a
37
- # constant-folded `Constant[120]` — full constant folding of the reduction is out of scope, the
38
- # precision target is the carrier (`Integer`), not the value.
37
+ # constant-folded `Constant[120]` — this nominal fold targets the carrier (`Integer`), not the value; a
38
+ # fully-constant receiver is folded to its value earlier, by `try_constant_reduce`.
39
39
  module ReduceFolding
40
40
  module_function
41
41
 
@@ -227,8 +227,7 @@ module Rigor
227
227
  # The seed itself is the result when the collection is empty (`[].reduce(s, :op) == s`), so a
228
228
  # 2-arg fold's static type is the operator result joined with the seed. The seed is widened
229
229
  # (`Constant[0]` -> `Integer`) for the join so the carrier stays the precision target rather than
230
- # leaking a value-pinned member (`0 | Integer`) — full constant folding of the fold is out of
231
- # scope.
230
+ # leaking a value-pinned member (`0 | Integer`).
232
231
  return result if seed.nil?
233
232
 
234
233
  Type::Combinator.union(Type::Combinator.widen_value_pinned(seed), result)
@@ -66,7 +66,7 @@ module Rigor
66
66
  # `Regexp.last_match` reads the same match-data slot the perlish `$~` global tracks. On a
67
67
  # proven-match edge — the truthy branch of `if str =~ /re/`, the surviving path of `unless /re/ =~
68
68
  # s; raise; end`, a `case`/`when` regex arm — the flow engine has already narrowed `$~` to a
69
- # non-nil `MatchData` (see `Narrowing#regex_match_predicate_scopes`). Upstream RBS types
69
+ # non-nil `MatchData` (see `RegexMatch.regex_match_predicate_scopes`). Upstream RBS types
70
70
  # `Regexp.last_match` as `() -> MatchData?` / `(int) -> String?`, so without this consult the call
71
71
  # drops back to the nilable return even where the surrounding flow has *proven* the match
72
72
  # succeeded — re-introducing the `possible nil receiver` the `$~` narrowing exists to remove the
@@ -94,7 +94,7 @@ module Rigor
94
94
  def typed_set(types)
95
95
  return nil if types.empty?
96
96
 
97
- members = types.map { |t| MethodDispatcher.array_new_element(t) }
97
+ members = types.map { |t| MetaIntrospection.array_new_element(t) }
98
98
  Type::Combinator.nominal_of("Set", type_args: [Type::Combinator.union(*members, Type::Combinator.untyped)])
99
99
  end
100
100
 
@@ -16,7 +16,8 @@ module Rigor
16
16
  # (non-static key, out-of-range index, multi-arg `dig`, ...) the tier returns `nil` so the
17
17
  # surrounding pipeline falls through to {RbsDispatch} and the projection-based answer.
18
18
  #
19
- # Catalogue (Slice 5 phase 2):
19
+ # Original catalogue (Slice 5 phase 2); `TUPLE_HANDLERS` and `HASH_SHAPE_HANDLERS` below are the current,
20
+ # much wider tables, and `RECEIVER_HANDLERS` lists the other receiver carriers the tier reads:
20
21
  #
21
22
  # - Tuple#`first`, Tuple#`last` (no-arg, or a single `Constant[Integer]` count lifting to a
22
23
  # sub-`Tuple`, the `take`/`drop` shape), Tuple#`size`/`length`/`count`: no-block.
@@ -197,8 +198,6 @@ module Rigor
197
198
  itself: :shape_self
198
199
  }.freeze
199
200
 
200
- # @return the precise element/value type, or `nil` to defer to the next
201
- # dispatcher tier.
202
201
  # Per-carrier dispatch table. Adding a new carrier here is a one-row change; the helper methods
203
202
  # stay private. Anonymous Type subclasses are not expected.
204
203
  RECEIVER_HANDLERS = {
@@ -214,6 +213,8 @@ module Rigor
214
213
  }.freeze
215
214
  private_constant :RECEIVER_HANDLERS
216
215
 
216
+ # @return the precise element/value type, or `nil` to defer to the next
217
+ # dispatcher tier.
217
218
  def try_dispatch(context)
218
219
  receiver = context.receiver
219
220
  method_name = context.method_name
@@ -331,7 +332,7 @@ module Rigor
331
332
  return nil unless SET_UNION_ALGEBRA.include?(method_name) && args.size == 1
332
333
 
333
334
  receiver = nominal.type_args.size == 1 ? nominal.type_args.first : Type::Combinator.untyped
334
- added = Inference::SetMutation.element_types(args.first).map { |t| MethodDispatcher.array_new_element(t) }
335
+ added = Inference::SetMutation.element_types(args.first).map { |t| MetaIntrospection.array_new_element(t) }
335
336
  Type::Combinator.nominal_of("Set", type_args: [Type::Combinator.union(receiver, *added)])
336
337
  end
337
338
 
@@ -633,10 +634,22 @@ module Rigor
633
634
 
634
635
  return difference if base.class_name == "String" &&
635
636
  NON_EMPTY_STRING_PRESERVING_UNARY.include?(method_name)
637
+ return non_empty_array_pop(base) if method_name == :pop
636
638
 
637
639
  non_zero_int_unary_projection(difference, base, method_name)
638
640
  end
639
641
 
642
+ # Issue #3338 — a `pop` with no argument on `non-empty-array[T]` removes an element that is there, so it
643
+ # answers `T` where core RBS spells `() -> E?`. `shift` / `first` / `last` / `sample` already read `E`
644
+ # through their `%a{implicitly-returns-nil}`; `pop` carries no such annotation. The refinement itself is
645
+ # dropped by `MutationWidening` after the call, so a second `pop` reads `T?` again. A stale fact (#3351)
646
+ # makes this answer `T` on an array that may be empty.
647
+ def non_empty_array_pop(base)
648
+ return nil unless base.class_name == "Array"
649
+
650
+ base.type_args.first
651
+ end
652
+
640
653
  def non_zero_int_unary_projection(difference, base, method_name)
641
654
  return nil unless base.class_name == "Integer"
642
655
  return Type::Combinator.positive_int if %i[abs magnitude].include?(method_name)
@@ -1397,8 +1410,6 @@ module Rigor
1397
1410
  false
1398
1411
  end
1399
1412
 
1400
- # `tuple + other` — concatenates two Tuples. Both sides must be `Type::Tuple`. Returns a new
1401
- # Tuple whose elements are those of the receiver followed by those of the argument.
1402
1413
  # `at(n)` — the strict single-Integer accessor. Deliberately NOT an alias of {#tuple_index}: `[]`
1403
1414
  # and `slice` accept a Range or a `(start, length)` pair, while `Array#at` raises `ArgumentError`
1404
1415
  # on anything but one Integer, and a fold must never invent a value for a call that raises.
@@ -1499,6 +1510,8 @@ module Rigor
1499
1510
  end
1500
1511
  # rubocop:enable Style/ReturnNilInPredicateMethodDefinition
1501
1512
 
1513
+ # `tuple + other` — concatenates two Tuples. Both sides must be `Type::Tuple`. Returns a new
1514
+ # Tuple whose elements are those of the receiver followed by those of the argument.
1502
1515
  def tuple_concat(tuple, _method_name, args)
1503
1516
  return nil unless args.size == 1
1504
1517
 
@@ -12,14 +12,14 @@ module Rigor
12
12
  # of them opens with the same two questions:
13
13
  #
14
14
  # 1. "Is the receiver the `Singleton[X]` I handle?" — a one-line
15
- # `is_a?(Type::Singleton) && class_name == "X"` that used to be copied verbatim into nine
16
- # modules.
15
+ # `is_a?(Type::Singleton) && class_name == "X"` that used to be copied verbatim into each
16
+ # of those modules.
17
17
  # 2. "Is this argument a foldable `Constant[String]`?" — the `is_a?(Type::Constant) &&
18
18
  # value.is_a?(String)` unwrap the string-folding tiers (CGI / URI / Shellwords / Regexp) gate on
19
19
  # before evaluating the literal.
20
20
  #
21
21
  # Centralising both here keeps the receiver-shape and constant-unwrap knowledge in one place: if
22
- # `Type::Singleton` or `Type::Constant` ever changes shape, there is a single edit rather than nine.
22
+ # `Type::Singleton` or `Type::Constant` ever changes shape, there is a single edit rather than one per tier.
23
23
  module SingletonFolding
24
24
  module_function
25
25
 
@@ -20,9 +20,12 @@ module Rigor
20
20
  # The rule is exact rather than heuristic — the receiver must be a `Singleton[C]` whose `C` the project
21
21
  # pre-pass recorded as including `Singleton` — so a class that does not include the mixin is untouched,
22
22
  # and a project that defines its own `Singleton` module is the one case that would misfire. Guarded by
23
- # {own_singleton_include?}: when the included name resolves to a project-declared class or module (a
24
- # top-level `Singleton`, or `M::Singleton` inside `module M`), the tier declines, because then the name
25
- # means something else entirely.
23
+ # {includes_singleton_mixin?}: when the included name resolves to a project-declared top-level `Singleton`,
24
+ # the tier declines, because then the name means something else entirely (a nested `M::Singleton` is read as
25
+ # the stdlib mixin; see that method).
26
+ #
27
+ # Its place in the order is `MethodDispatcher`'s `BUNDLED_OVERRIDE_TIERS`, the last of them, ahead of
28
+ # `RbsDispatch`.
26
29
  module SingletonMixinDispatch
27
30
  MIXIN_NAMES = Ractor.make_shareable(Set["Singleton", "::Singleton"])
28
31
  private_constant :MIXIN_NAMES
@@ -40,7 +43,7 @@ module Rigor
40
43
  Type::Combinator.nominal_of(receiver.class_name)
41
44
  end
42
45
 
43
- # Issue #2438 — the one predicate behind {try_dispatch} and `CheckRules#undefined_method_diagnostic`, so the
46
+ # Issue #2438 — the one predicate behind {try_dispatch} and `CheckRules::UndefinedMethod.diagnostic`, so the
44
47
  # typer and the `call.undefined-method` rule cannot disagree about `C.instance`: a call this tier types is
45
48
  # never reported as undefined, whatever a project sidecar of `C` lists.
46
49
  def answers?(scope, receiver, method_name, no_arguments)