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,212 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../type"
4
+ require_relative "../refined_dispatch"
5
+
6
+ module Rigor
7
+ module Inference
8
+ module CallLadder
9
+ # The `refined` rung of the call ladder (ADR-116 WD12; ADR-121): a call through a Ruby refinement in effect at
10
+ # the call site, answered from the winning refine body ahead of every other rung. `ExpressionTyper` asks it first
11
+ # in a call's ladder, directly behind indexed and method-chain narrowing. {ExpressionTyper} is not required here:
12
+ # it requires this file. Nor is {InEffectRefinements}: `Scope` requires it, and it cannot load ahead of `Scope`.
13
+ #
14
+ # {.try_call} is the rung, asked with the call's site and the walking typer, and the module's one entry: only the
15
+ # ladder's entries ask it, so it has no second entry. Every other function is private to the module.
16
+ #
17
+ # The module holds no state. It reads the scope as `typer.scope` and calls back three methods of the typer:
18
+ # `positional_correspondence` and `infer_user_method_return`, which re-type the winning refine body, and
19
+ # `call_result_type_for`, the call's ladder, which a union receiver re-enters for each member no refinement wins.
20
+ # `CallLadder::PORT` lists them. A function that only reads the scope takes it as a parameter and never sees the
21
+ # typer.
22
+ module Refined
23
+ module_function
24
+
25
+ # ADR-121 WD2 (issue #1664) — a call through an in-effect Ruby refinement, typed from the winning refine body
26
+ # with the call's receiver as `self`, ahead of every tier below: each answers from the method the refinement
27
+ # replaces (a refined `String#upcase` must not fold, a refined `map` must not fold per element, a top-level
28
+ # `def` must not bind ahead of a refinement of `Object`, a plugin models the class's own method). An unreadable
29
+ # body, or a list that may hold any refinement, answers `Dynamic[top]`, never the replaced method's signature.
30
+ # A union receiver is decided per member; a `Dynamic` receiver and a call no refinement wins fall through. A
31
+ # class object walks its own lookup (issue #1752): under `refine(Object) { def oo = :o }` a refinement that wins
32
+ # `Integer.oo` answers `Dynamic[top]` ({.refined_class_object_result}). A call site no refinement is in effect
33
+ # at answers nil at once and records nothing: its answer cannot change without an edit to its own file.
34
+ #
35
+ # ADR-121 WD7 (A2) — inside the span of an activation that puts an opaque module in effect
36
+ # ({InEffectRefinements.opaque_module?}), any method of any object may be replaced, so every call on an instance
37
+ # or a class object answers `Dynamic[top]`.
38
+ #
39
+ # The rung, asked with the call's site. The method name is the site's, not the call node's, and so are the
40
+ # receiver, the argument types and the block type. The call node is read for where the call stands (the
41
+ # refinements in effect there, the span of an opaque activation) and for what it writes (a literal name
42
+ # argument, a `&:name` block, the arguments a refine body is bound to).
43
+ def try_call(site, typer)
44
+ node = site.call_node
45
+ receiver = site.receiver
46
+ arg_types = site.args
47
+ method_name = site.method_name
48
+ block_type = site.block_type
49
+ list = typer.scope.in_effect_refinements(node)
50
+ return nil if list.empty?
51
+
52
+ InEffectRefinements.record_refinement_names(method_name)
53
+ if refined_receiver?(receiver) && opaque_refinement_span?(node, list, typer.scope)
54
+ return Type::Combinator.untyped
55
+ end
56
+ return nil if typer.scope.discovered_refinements.empty?
57
+
58
+ refined_indirect_result(node, receiver, list, method_name, typer.scope) ||
59
+ refined_receiver_result(node, receiver, list, arg_types, block_type, method_name, typer)
60
+ end
61
+
62
+ # ADR-121 WD4 — `send` / `__send__` / `public_send` with a literal name, `respond_to?` and `method` /
63
+ # `public_method` with one, and a `&:name` block argument honour refinements too (CRuby `test_refinement.rb`;
64
+ # probed on Ruby 4.0.5). When the name they reach is refined in effect for the receiver they answer
65
+ # `Dynamic[top]`: typing them through the arm is deferred, and `respond_to?` must never fold to `false`. A
66
+ # `&:name` block's receiver is the yielded element, which is not known here, so any in-effect refinement of the
67
+ # name answers. Only `methods` ignores refinements and keeps its answer.
68
+ def refined_indirect_result(node, receiver, list, method_name, scope)
69
+ name = REFINED_NAMING_CALLS.include?(method_name) ? literal_method_name_argument(node) : nil
70
+ return Type::Combinator.untyped if name && refined_name_for?(receiver, name, list, scope)
71
+
72
+ block_name = symbol_block_argument(node)
73
+ Type::Combinator.untyped if block_name && RefinedDispatch.refined_anywhere?(scope, block_name, list)
74
+ end
75
+
76
+ REFINED_NAMING_CALLS = Set[:send, :__send__, :public_send, :respond_to?, :method, :public_method].freeze
77
+ private_constant :REFINED_NAMING_CALLS
78
+
79
+ def literal_method_name_argument(node)
80
+ argument = node.arguments&.arguments&.first
81
+ name = argument.unescaped if argument.is_a?(Prism::SymbolNode) || argument.is_a?(Prism::StringNode)
82
+ return nil if name.nil?
83
+
84
+ name = name.to_sym
85
+ InEffectRefinements.record_refinement_names(name)
86
+ name
87
+ end
88
+
89
+ def symbol_block_argument(node)
90
+ block = node.block
91
+ return nil unless block.is_a?(Prism::BlockArgumentNode) && block.expression.is_a?(Prism::SymbolNode)
92
+
93
+ name = block.expression.unescaped.to_sym
94
+ InEffectRefinements.record_refinement_names(name)
95
+ name
96
+ end
97
+
98
+ def refined_name_for?(receiver, name, list, scope)
99
+ members = receiver.is_a?(Type::Union) ? receiver.members : [receiver]
100
+ members.any? do |member|
101
+ next !RefinedDispatch.winner(scope, member.class_name, name, list, kind: :singleton).nil? if
102
+ member.is_a?(Type::Singleton)
103
+
104
+ class_name = refined_receiver_class_name(member)
105
+ !class_name.nil? && !RefinedDispatch.winner(scope, class_name, name, list).nil?
106
+ end
107
+ end
108
+
109
+ # ADR-121 WD7 — does the call's lexical list (a plugin-declared module is the plugin's declaration and never
110
+ # opaque) hold an opaque module? `list` is the full list, which is the lexical one when nothing is declared.
111
+ def opaque_refinement_span?(node, list, scope)
112
+ lexical =
113
+ scope.declared_refinements.empty? ? list : scope.in_effect_refinements(node, InEffectRefinements::EMPTY)
114
+ InEffectRefinements.opaque_in?(scope, lexical)
115
+ end
116
+
117
+ # Does `receiver` (or a member of a union) have a lookup the refined arm answers for: an instance of a class,
118
+ # or a class object (issue #1752), not `Dynamic`?
119
+ def refined_receiver?(receiver)
120
+ members = receiver.is_a?(Type::Union) ? receiver.members : [receiver]
121
+ members.any? { |member| member.is_a?(Type::Singleton) || !refined_receiver_class_name(member).nil? }
122
+ end
123
+
124
+ # A union receiver is decided per member, and a member no refinement wins re-enters the call's ladder with that
125
+ # member as the receiver (`ExpressionTyper#call_result_type_for`, a re-entry point of the port).
126
+ def refined_receiver_result(node, receiver, list, arg_types, block_type, method_name, typer)
127
+ unless receiver.is_a?(Type::Union)
128
+ return refined_member_result(node, receiver, list, arg_types, block_type, method_name, typer)
129
+ end
130
+
131
+ answers = receiver.members.map do |member|
132
+ refined_member_result(node, member, list, arg_types, block_type, method_name, typer)
133
+ end
134
+ return nil if answers.none?
135
+
136
+ members = receiver.members.each_with_index.map do |member, index|
137
+ answers[index] || typer.call_result_type_for(node, receiver_override: member)
138
+ end
139
+ Type::Combinator.union(*members)
140
+ end
141
+
142
+ def refined_member_result(node, receiver, list, arg_types, block_type, method_name, typer)
143
+ if receiver.is_a?(Type::Singleton)
144
+ return refined_class_object_result(node, receiver, list, arg_types, block_type, method_name, typer.scope)
145
+ end
146
+
147
+ class_name = refined_receiver_class_name(receiver)
148
+ return nil if class_name.nil?
149
+
150
+ winner = RefinedDispatch.winner(typer.scope, class_name, method_name, list)
151
+ return nil if winner.nil?
152
+ return Type::Combinator.untyped if winner == RefinedDispatch::UNKNOWN
153
+
154
+ refined_body_return(winner, node, Type::Combinator.nominal_of(class_name), arg_types, block_type, method_name,
155
+ typer) || Type::Combinator.untyped
156
+ end
157
+
158
+ # Issue #1752 — a call on a class object, walked through its singleton levels. A refinement that wins answers
159
+ # `Dynamic[top]`, never its refine body's type: a hook on any ancestor (an RBS-declared `include Singleton`, a
160
+ # gem concern, `define_singleton_method(:included)`, a `Module#included` patch) can install the class object's
161
+ # own method where no table sees it, and the body's type then fires downstream on correct code. A walk that
162
+ # finds no winner keeps the class object's own answer (`Integer.sqrt(16)` stays `Integer`).
163
+ def refined_class_object_result(_node, receiver, list, _arg_types, _block_type, method_name, scope)
164
+ winner = RefinedDispatch.winner(scope, receiver.class_name, method_name, list, kind: :singleton)
165
+ Type::Combinator.untyped unless winner.nil?
166
+ end
167
+
168
+ # The winning refine body's inferred return, re-typed with the receiver's class as `self` and the call's
169
+ # argument types bound as an undeclared method's are; nil when the body is not readable here.
170
+ #
171
+ # A body another file wrote is re-typed with that file's in-effect refinements at the `def` (its own module
172
+ # among them), so a sibling override it calls answers from its refine body too.
173
+ def refined_body_return(winner, call_node, self_type, arg_types, block_type, method_name, typer)
174
+ def_node, foreign =
175
+ InEffectRefinements.refinement_def_with_query(typer.scope, winner.module_name, winner.refined_class,
176
+ method_name)
177
+ return nil if def_node.nil?
178
+
179
+ refinements = foreign&.at(def_node.location.start_offset) do |name|
180
+ InEffectRefinements.activated_modules(typer.scope, name)
181
+ end
182
+ arg_types, positionals_unknown = typer.positional_correspondence(call_node, arg_types)
183
+ typer.infer_user_method_return(def_node, self_type, arg_types, yield_type: block_type,
184
+ refinements: refinements,
185
+ positionals_unknown: positionals_unknown)
186
+ rescue StandardError
187
+ nil
188
+ end
189
+
190
+ # The class an instance-side receiver is an instance of, or nil for one this instance walk does not answer: a
191
+ # class object (it walks its own lookup, {.refined_class_object_result}), `Dynamic`, `top`, or a shape with no
192
+ # class.
193
+ def refined_receiver_class_name(receiver)
194
+ case receiver
195
+ when Type::Nominal, Type::StructInstance, Type::DataInstance then receiver.class_name
196
+ when Type::Constant then receiver.value.class.name
197
+ when Type::Tuple then "Array"
198
+ when Type::HashShape then "Hash"
199
+ when Type::IntegerRange then "Integer"
200
+ when Type::FloatRange then "Float"
201
+ when Type::Refined, Type::Difference then refined_receiver_class_name(receiver.base)
202
+ end
203
+ end
204
+
205
+ private_class_method :refined_indirect_result, :literal_method_name_argument, :symbol_block_argument,
206
+ :refined_name_for?, :opaque_refinement_span?, :refined_receiver?, :refined_receiver_result,
207
+ :refined_member_result, :refined_class_object_result, :refined_body_return,
208
+ :refined_receiver_class_name
209
+ end
210
+ end
211
+ end
212
+ end
@@ -0,0 +1,222 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../type"
4
+ require_relative "../external_ancestor_resolution"
5
+ require_relative "../method_dispatcher"
6
+
7
+ module Rigor
8
+ module Inference
9
+ module CallLadder
10
+ # The `top_level_def` rung of the call ladder (ADR-116 WD12): an implicit-self call of a name the project defines
11
+ # as a top-level `def`, answered by re-typing that `def`'s body, where the call's own `self` does not answer the
12
+ # name itself. `ExpressionTyper` asks it in a call's ladder, behind the literal-`send` rung. {ExpressionTyper} is
13
+ # not required here: it requires this file, and `Scope` is loaded before either.
14
+ #
15
+ # {.try_call} is the rung, asked with the call's site and the walking typer, and the module's one entry: only the
16
+ # ladder's entries ask it, so it has no second entry. Every other function is private to the module.
17
+ #
18
+ # The module holds no state. It reads the scope as `typer.scope` and calls back three methods of the typer:
19
+ # `positional_correspondence` and `infer_user_method_return`, which re-type the body, and
20
+ # `resolve_user_def_through_ancestors`, which the instance-side veto asks. `CallLadder::PORT` lists them. A
21
+ # function that only reads the scope takes it as a parameter and never sees the typer.
22
+ module TopLevelDef
23
+ module_function
24
+
25
+ # v0.0.3 A — implicit-self calls prefer a same-named top-level `def` over RBS dispatch. Without this, a
26
+ # helper like `def select(...)` defined inside an `RSpec.describe ... do ... end` block mis-routes
27
+ # through `Enumerable#select` / `Object#select` and the caller observes `Array[Elem]` instead of the
28
+ # helper's actual return type. The check fires only for `node.receiver.nil?` (true implicit self), so
29
+ # explicit-receiver dispatch is unaffected.
30
+ #
31
+ # Issue #316 — the lookup goes through the confidence-gated `Scope#bindable_top_level_def_for`, not the
32
+ # raw table: inside a block whose `self` is unmodelled, a top-level `def` from ANOTHER file is not
33
+ # evidence about which method the call reaches, so the bind is declined and the call widens.
34
+ #
35
+ # Issue #618 — the binding is a fallback for names the enclosing `self` does NOT answer, not a
36
+ # first-choice tier. A top-level `def` is a private method on `Object`, the last link of every MRO, so
37
+ # whenever the call's own `self` carries the name the class wins at runtime and the top-level body is
38
+ # never reached. Binding regardless of `self_type` inverted that: a top-level `def text` typed the
39
+ # member read inside `class Line < Struct.new(:text); def shout = text.upcase; end` as the def's `nil`
40
+ # and fired `undefined method 'upcase' for nil` on correct code. The candidate is still looked up
41
+ # first — that lookup is a hash probe and owns the ADR-46 cross-file dependency edge — and
42
+ # {.self_type_answers?} then vetoes the bind for a name the enclosing class answers itself.
43
+ #
44
+ # Issue #963 item 2 — {.plugin_member_answers?} is the second veto, for the members no source the
45
+ # engine walks can enumerate: a plugin's `dynamic_return` answer and the ADR-16 synthetic-method
46
+ # index. They are members of `self` exactly as an `attr_reader` is, so a top-level `def` must not
47
+ # bind ahead of them either.
48
+ #
49
+ # Issue #2861 — a bind the #316 gate declines answers `Dynamic[Top]`, never the RBS method of the same name: the
50
+ # block's real `self` reaches either a same-named method of its own or the top-level `def`, which shadows
51
+ # `Kernel#format` and every other `Object` / `Kernel` method on the way. Falling through typed
52
+ # `format(r).bit_length` against `Kernel#format`'s `String` on code that runs the project's `def format`.
53
+ #
54
+ # The rung, asked with the call's site. The method name is the site's, not the call node's, and so are the
55
+ # receiver, the argument types and the block type.
56
+ def try_call(site, typer)
57
+ node = site.call_node
58
+ receiver = site.receiver
59
+ arg_types = site.args
60
+ method_name = site.method_name
61
+ block_type = site.block_type
62
+ return nil unless node.receiver.nil?
63
+
64
+ local_def = typer.scope.bindable_top_level_def_for(method_name)
65
+ return declined_top_level_def_answer(method_name, typer.scope) if local_def.nil?
66
+ return nil if self_type_answers?(method_name, typer)
67
+ return nil if plugin_member_answers?(node, receiver, method_name, typer.scope)
68
+
69
+ local_inference = infer_top_level_user_method(local_def, receiver, node, arg_types, block_type, typer)
70
+ return local_inference if local_inference
71
+
72
+ # The local def matches by name but the inference was disqualified — the parameter shape is too
73
+ # complex for the first-iteration binder (kwargs / optionals / rest), so the body could not be
74
+ # re-typed. `Dynamic[Top]` is the safest answer: RBS dispatch would be wrong (the method is
75
+ # user-defined and shadows whatever ancestor method the dispatch would find), and `Dynamic[Top]`
76
+ # propagates correctly through downstream call chains without surfacing misleading false-positive
77
+ # diagnostics.
78
+ Type::Combinator.untyped
79
+ end
80
+
81
+ # Issue #2861 — the answer for an implicit-self call whose top-level `def` the #316 gate declined: nil (dispatch
82
+ # as before) when the project defines no top-level `def` of the name, else `Dynamic[Top]`. The gate declines
83
+ # only where `self_type` is nil, so no member of `self` ({.self_type_answers?}, {.plugin_member_answers?}) can
84
+ # answer.
85
+ def declined_top_level_def_answer(method_name, scope)
86
+ return nil unless scope.opaque_block_self? && scope.self_type.nil?
87
+ return nil if scope.top_level_def_for(method_name).nil?
88
+
89
+ Type::Combinator.untyped
90
+ end
91
+
92
+ # v0.0.3 A — re-types a top-level (or DSL-block-nested) `def` discovered by `ScopeIndexer` under the
93
+ # `TOP_LEVEL_DEF_KEY` sentinel. Mirrors the `infer_user_method_return` shape but uses the current
94
+ # `scope.self_type` (or implicit `Object`) as the receiver carrier so the body's own self is
95
+ # consistent with the call site's. Returns nil when the parameter shape disqualifies the def, when the
96
+ # body is empty, or when the inference raises.
97
+ def infer_top_level_user_method(def_node, receiver, call_node, arg_types, block_type, typer)
98
+ arg_types, positionals_unknown = typer.positional_correspondence(call_node, arg_types)
99
+ typer.infer_user_method_return(def_node, receiver, arg_types, yield_type: block_type,
100
+ positionals_unknown: positionals_unknown)
101
+ rescue StandardError
102
+ nil
103
+ end
104
+
105
+ # Issue #618 — whether the call's enclosing `self` already answers `method_name`. Only a `self` whose
106
+ # class is KNOWN participates: at genuine top level, and inside a block whose `self` is unmodelled,
107
+ # `scope.self_type` is nil, the predicate is false, and the historical top-level binding stands — that
108
+ # is #316's / #319's territory and this veto stays out of it.
109
+ #
110
+ # The ADR-48 member carriers answer from their own map first: a `StructInstance` / `DataInstance`
111
+ # `self` carries the member set the body reads through, and an anonymous `Struct.new(...)` value has no
112
+ # class name to look anything else up under.
113
+ def self_type_answers?(method_name, typer)
114
+ case (self_type = typer.scope.self_type)
115
+ when Type::Singleton then singleton_self_answers?(self_type.class_name, method_name, typer.scope)
116
+ when Type::Nominal then instance_self_answers?(self_type.class_name, method_name, typer)
117
+ when Type::StructInstance, Type::DataInstance
118
+ self_type.members.key?(method_name.to_sym) || instance_self_answers?(self_type.class_name, method_name,
119
+ typer)
120
+ else false
121
+ end
122
+ end
123
+
124
+ # Issue #963 item 2 — the plugin arm of the veto: whether a plugin answers `method_name` on the call's
125
+ # own `self`. Asked of `MethodDispatcher.plugin_member_answers?`, which puts the question to the same
126
+ # two tiers dispatch would consult (the gated `dynamic_return` walk and the ADR-16 synthetic-method
127
+ # index), so the veto carries no plugin knowledge of its own.
128
+ #
129
+ # The confidence gate is #618's, unchanged and re-stated here rather than inherited: only a `self`
130
+ # whose class is KNOWN participates. At genuine top level, and inside a block whose `self` is
131
+ # unmodelled, `scope.self_type` is nil, `receiver` is the synthetic `Object` / `Dynamic[Top]` stand-in
132
+ # that {ExpressionTyper#call_receiver_type_for} substitutes, and asking a plugin about THAT receiver would be
133
+ # asking about a `self` the engine has not modelled — #316's / #319's territory, which this stays out of.
134
+ def plugin_member_answers?(node, receiver, method_name, scope)
135
+ return false if scope.self_type.nil?
136
+
137
+ MethodDispatcher.plugin_member_answers?(
138
+ call_node: node, scope: scope, receiver_type: receiver, method_name: method_name
139
+ )
140
+ end
141
+
142
+ # The instance side of {.self_type_answers?}: the discovered methods (`def`, `attr_*`,
143
+ # `define_method`, `alias`) of the class or any project ancestor, its `Struct.new` / `Data.define`
144
+ # member accessors, a `def` reached through its project ancestors (superclass chain and included
145
+ # modules), and an RBS method declared on an owner that PRECEDES `::Object` in the MRO.
146
+ #
147
+ # Issue #633 — the discovery arm walks ancestors because inheritance does not distinguish how a
148
+ # method got there: a superclass `attr_accessor :stext` and an included module's `attr_reader` bind
149
+ # ahead of a top-level `def stext` exactly as an inherited `def` does, and only the latter had a walk.
150
+ #
151
+ # The RBS arm's cut-off is `::Object`, not the own class. A top-level `def` IS a private `Object`
152
+ # instance method, the last link of every MRO, so any declared owner that comes before `::Object`
153
+ # wins at runtime — `Exception#message` for a `StandardError` subclass, `Array#first`,
154
+ # `Comparable#clamp`. What the cut-off keeps out is the tier v0.0.3 A exists for and #316 / #319
155
+ # refined: a name owned by `Object` or `Kernel` themselves (`inspect`, `format`) is at or after the
156
+ # top-level `def`'s own rung, so the historical binding still stands there.
157
+ def instance_self_answers?(class_name, method_name, typer)
158
+ return false if class_name.nil?
159
+ return true if typer.scope.discovered_method_through_ancestors?(class_name, method_name, :instance)
160
+ return true if meta_member?(class_name, method_name, typer.scope)
161
+ return true if typer.resolve_user_def_through_ancestors(class_name, method_name)
162
+ return true if rbs_ancestor_answers?(class_name, method_name, typer.scope)
163
+
164
+ # Issue #2968 — a class on the chain defines methods under names no table holds (`attr_accessor(*FLAGS)`, a
165
+ # splatted `Struct.new(*FIELDS)`), so the name may be one of them, ahead of the top-level `def`.
166
+ return true if Scope::DiscoveryIndex.open_names_on_chain?(typer.scope, class_name, :instance)
167
+
168
+ # Issue #2994 — a class on the chain mixes in a module no table names (`include(*MODS)`, `include helper`),
169
+ # so the name may be that module's, ahead of the top-level `def`.
170
+ Scope::DiscoveryIndex.unnamed_mixin_on_chain?(typer.scope, class_name)
171
+ end
172
+
173
+ # The RBS arm of {.instance_self_answers?}. A project class is usually absent from the RBS
174
+ # environment, so the declaration that decides the question is written about an ancestor the project
175
+ # does not declare (`StandardError`, `Array`, `Comparable`) — each is asked on its own terms, and
176
+ # each of them is itself before `::Object` in the reader's MRO by construction.
177
+ #
178
+ # Issue #527 slice 0 — the walk itself lives in {ExternalAncestorResolution}, which reports WHICH
179
+ # declaration answered because the dispatch side needs to dispatch there. This tier only needs to
180
+ # know that one did, so it reads the presence of an answer. Dependency recording stays ON: this
181
+ # arm genuinely read the ancestor's declaration to decide the binding.
182
+ def rbs_ancestor_answers?(class_name, method_name, scope)
183
+ !ExternalAncestorResolution.resolve(class_name, method_name, :instance, scope: scope).nil?
184
+ end
185
+
186
+ # The singleton side: a class-body `self` is `Singleton[Foo]`, where an implicit-self call reaches
187
+ # `Foo`'s own class methods before `Object`'s private top-level `def`.
188
+ #
189
+ # Issue #633 — both discovery arms follow the superclass chain, because a subclass inherits its
190
+ # parent's class methods; `Scope` narrows the singleton walk to superclasses for the same reason
191
+ # (an `include`d module's `def self.x` is not callable on the includer).
192
+ def singleton_self_answers?(class_name, method_name, scope)
193
+ return false if class_name.nil?
194
+ return true if scope.discovered_method_through_ancestors?(class_name, method_name, :singleton)
195
+ return true unless scope.singleton_def_through_ancestors(class_name, method_name).first.nil?
196
+
197
+ declared = ExternalAncestorResolution.method_definition(class_name, method_name, :singleton, scope: scope)
198
+ return true if ExternalAncestorResolution.declared_on_class?(declared, class_name)
199
+
200
+ # Issue #2994 — a class object on the chain that a module no table names may extend through a hook (the
201
+ # `:include_hook` open mark of a class with `include(*MODS)`), a class that `extend(*EMODS)`s, or an extended
202
+ # module whose own module set is unknown, may answer any name ahead of the top-level `def`.
203
+ Scope::ResolutionChain.for(scope, class_name.to_s, :singleton, :methods).unnamed_mixin?
204
+ end
205
+
206
+ # A `Struct.new(:a, :b)` / `Data.define(:a, :b)` member accessor. The layouts are a discovery table of
207
+ # their own, separate from `discovered_methods`, so the accessor names they imply have to be asked for
208
+ # explicitly. Only the reader name is tested: a writer is unreachable as an implicit-self call, since
209
+ # bare `a = v` is a local assignment.
210
+ def meta_member?(class_name, method_name, scope)
211
+ layout = scope.struct_member_layout(class_name)
212
+ members = layout ? layout[:members] : scope.data_member_layout(class_name)
213
+ !members.nil? && members.include?(method_name.to_sym)
214
+ end
215
+
216
+ private_class_method :declined_top_level_def_answer, :infer_top_level_user_method, :self_type_answers?,
217
+ :plugin_member_answers?, :instance_self_answers?, :rbs_ancestor_answers?,
218
+ :singleton_self_answers?, :meta_member?
219
+ end
220
+ end
221
+ end
222
+ end