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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/docs/handbook/01-getting-started.md +1 -1
- data/docs/handbook/04-tuples-and-shapes.md +6 -1
- data/docs/handbook/12-lightweight-hkt.md +1 -1
- data/docs/handbook/appendix-typescript.md +28 -17
- data/docs/manual/02-cli-reference.md +10 -0
- data/docs/manual/03-configuration.md +1 -1
- data/docs/manual/04-diagnostics.md +1 -1
- data/docs/manual/10-mcp-server.md +122 -10
- data/docs/manual/plugins/rigor-activerecord.md +7 -0
- data/lib/rigor/analysis/check_rules/always_raises.rb +95 -0
- data/lib/rigor/analysis/check_rules/always_truthy_condition_collector.rb +32 -2
- data/lib/rigor/analysis/check_rules/argument_type.rb +802 -0
- data/lib/rigor/analysis/check_rules/call_facts.rb +2 -2
- data/lib/rigor/analysis/check_rules/dead_assignment_collector.rb +30 -1
- data/lib/rigor/analysis/check_rules/declaration_sourced_guard.rb +4 -5
- data/lib/rigor/analysis/check_rules/duplicate_hash_key_collector.rb +34 -0
- data/lib/rigor/analysis/check_rules/ivar_write_collector.rb +131 -4
- data/lib/rigor/analysis/check_rules/nil_receiver.rb +195 -0
- data/lib/rigor/analysis/check_rules/override_param_narrowed.rb +111 -0
- data/lib/rigor/analysis/check_rules/override_return_widened.rb +88 -0
- data/lib/rigor/analysis/check_rules/override_support.rb +246 -0
- data/lib/rigor/analysis/check_rules/override_visibility.rb +135 -0
- data/lib/rigor/analysis/check_rules/published_constant_guard.rb +75 -31
- data/lib/rigor/analysis/check_rules/raise_non_exception.rb +198 -0
- data/lib/rigor/analysis/check_rules/receiver_predicates.rb +576 -0
- data/lib/rigor/analysis/check_rules/return_in_ensure_collector.rb +52 -4
- data/lib/rigor/analysis/check_rules/return_type.rb +225 -0
- data/lib/rigor/analysis/check_rules/rigor_testing.rb +119 -0
- data/lib/rigor/analysis/check_rules/rule_ids.rb +7 -7
- data/lib/rigor/analysis/check_rules/rule_walk.rb +4 -3
- data/lib/rigor/analysis/check_rules/self_closedness_scanner.rb +2 -0
- data/lib/rigor/analysis/check_rules/self_undefined_method.rb +165 -0
- data/lib/rigor/analysis/check_rules/shadowed_rescue_collector.rb +34 -0
- data/lib/rigor/analysis/check_rules/source_arity.rb +2 -2
- data/lib/rigor/analysis/check_rules/special_global_write.rb +256 -0
- data/lib/rigor/analysis/check_rules/suppression.rb +275 -0
- data/lib/rigor/analysis/check_rules/undefined_method.rb +882 -0
- data/lib/rigor/analysis/check_rules/unreachable_branch.rb +97 -0
- data/lib/rigor/analysis/check_rules/unreachable_clause_collector.rb +42 -0
- data/lib/rigor/analysis/check_rules/unresolved_toplevel.rb +140 -0
- data/lib/rigor/analysis/check_rules/visibility_mismatch.rb +252 -0
- data/lib/rigor/analysis/check_rules/void_value_use_collector.rb +27 -0
- data/lib/rigor/analysis/check_rules/wrong_arity.rb +303 -0
- data/lib/rigor/analysis/check_rules.rb +66 -4931
- data/lib/rigor/analysis/dependency_recorder.rb +1 -1
- data/lib/rigor/analysis/dependency_source_inference/builder.rb +2 -4
- data/lib/rigor/analysis/dependency_source_inference/gem_resolver.rb +1 -2
- data/lib/rigor/analysis/dependency_source_inference/walker.rb +15 -15
- data/lib/rigor/analysis/incremental_session.rb +4 -4
- data/lib/rigor/analysis/path_expansion.rb +1 -1
- data/lib/rigor/analysis/plugin_fact_fingerprint.rb +5 -5
- data/lib/rigor/analysis/reachability/graph.rb +2 -3
- data/lib/rigor/analysis/reachability/plugin_roots.rb +2 -2
- data/lib/rigor/analysis/reachability/scan.rb +2 -2
- data/lib/rigor/analysis/rule_catalog.rb +2 -1
- data/lib/rigor/analysis/run_cache_key.rb +9 -8
- data/lib/rigor/analysis/runner/buffer_pool_dispatcher.rb +2 -2
- data/lib/rigor/analysis/runner/dependency_rows.rb +206 -0
- data/lib/rigor/analysis/runner/diagnostic_aggregator.rb +24 -22
- data/lib/rigor/analysis/runner/effect_cache_entries.rb +69 -0
- data/lib/rigor/analysis/runner/pool_coordinator.rb +6 -8
- data/lib/rigor/analysis/runner/project_pre_passes.rb +3 -5
- data/lib/rigor/analysis/runner/scope_seed.rb +144 -0
- data/lib/rigor/analysis/runner.rb +49 -296
- data/lib/rigor/analysis/template_unit_collector.rb +1 -1
- data/lib/rigor/analysis/template_units.rb +10 -10
- data/lib/rigor/analysis/worker_session.rb +7 -7
- data/lib/rigor/bleeding_edge.rb +3 -2
- data/lib/rigor/builtins/hkt_builtins.rb +17 -17
- data/lib/rigor/builtins/imported_refinements.rb +8 -16
- data/lib/rigor/builtins/regex_refinement.rb +3 -3
- data/lib/rigor/builtins/static_return_refinements.rb +143 -19
- data/lib/rigor/cache/incremental_snapshot.rb +21 -8
- data/lib/rigor/cache/rbs_descriptor.rb +18 -1
- data/lib/rigor/cli/coverage_renderer.rb +15 -1
- data/lib/rigor/cli/coverage_report.rb +19 -1
- data/lib/rigor/cli/diagnostic_formats.rb +3 -2
- data/lib/rigor/cli/docs_command.rb +5 -5
- data/lib/rigor/cli/effects_command.rb +7 -6
- data/lib/rigor/cli/fused_protection_report.rb +7 -7
- data/lib/rigor/cli/lsp_command.rb +1 -1
- data/lib/rigor/cli/mcp_command.rb +5 -2
- data/lib/rigor/cli/options.rb +4 -0
- data/lib/rigor/cli/plugins_command.rb +1 -1
- data/lib/rigor/cli/sig_gen_command.rb +1 -1
- data/lib/rigor/cli/skill_command.rb +5 -4
- data/lib/rigor/cli/triage_renderer.rb +3 -2
- data/lib/rigor/cli/unused_command.rb +4 -4
- data/lib/rigor/cli.rb +14 -0
- data/lib/rigor/configuration/coercion.rb +418 -0
- data/lib/rigor/configuration/defaults.rb +248 -0
- data/lib/rigor/configuration/dependencies.rb +1 -1
- data/lib/rigor/configuration/loader.rb +354 -0
- data/lib/rigor/configuration/severity_profile.rb +4 -4
- data/lib/rigor/configuration.rb +51 -860
- data/lib/rigor/effects/attribution.rb +1 -1
- data/lib/rigor/effects/effect_table.rb +1 -1
- data/lib/rigor/effects/identity.rb +3 -3
- data/lib/rigor/effects/local_ownership.rb +2 -2
- data/lib/rigor/effects/snapshot.rb +1 -1
- data/lib/rigor/effects/summary.rb +5 -4
- data/lib/rigor/environment/member_consistency.rb +10 -0
- data/lib/rigor/environment/rbs_loader.rb +19 -22
- data/lib/rigor/environment/reflection.rb +1 -1
- data/lib/rigor/environment/unreadable_signature.rb +21 -0
- data/lib/rigor/environment.rb +8 -8
- data/lib/rigor/flow_contribution/merger.rb +1 -0
- data/lib/rigor/hashing/xxh3.rb +1 -1
- data/lib/rigor/inference/acceptance.rb +23 -2
- data/lib/rigor/inference/alias_mutation_floor/site_collector.rb +5 -0
- data/lib/rigor/inference/alias_mutation_floor.rb +0 -5
- data/lib/rigor/inference/anonymous_meta_class.rb +2 -2
- data/lib/rigor/inference/block_call_timing.rb +6 -0
- data/lib/rigor/inference/budget_trace.rb +3 -2
- data/lib/rigor/inference/builtins/date_catalog.rb +3 -3
- data/lib/rigor/inference/builtins/method_catalog.rb +3 -3
- data/lib/rigor/inference/builtins/time_catalog.rb +3 -3
- data/lib/rigor/inference/call_ladder/literal_send.rb +98 -0
- data/lib/rigor/inference/call_ladder/overriding_def.rb +98 -0
- data/lib/rigor/inference/call_ladder/project_singleton.rb +362 -0
- data/lib/rigor/inference/call_ladder/refined.rb +212 -0
- data/lib/rigor/inference/call_ladder/top_level_def.rb +222 -0
- data/lib/rigor/inference/call_ladder/user_method.rb +247 -0
- data/lib/rigor/inference/call_ladder.rb +219 -0
- data/lib/rigor/inference/callee_write_census.rb +2 -2
- data/lib/rigor/inference/captured_locals.rb +2 -2
- data/lib/rigor/inference/clause_widening.rb +63 -1
- data/lib/rigor/inference/declaration_walk/context.rb +12 -12
- data/lib/rigor/inference/declaration_walk/rules.rb +750 -0
- data/lib/rigor/inference/declaration_walk/traversal.rb +9 -8
- data/lib/rigor/inference/declaration_walk.rb +4 -3
- data/lib/rigor/inference/def_node_resolver.rb +2 -2
- data/lib/rigor/inference/def_return_typer.rb +14 -6
- data/lib/rigor/inference/deferred_mutation.rb +120 -0
- data/lib/rigor/inference/define_method_block_self.rb +1 -1
- data/lib/rigor/inference/definer_resolution.rb +4 -4
- data/lib/rigor/inference/error_info.rb +8 -8
- data/lib/rigor/inference/expression_typer/composites.rb +348 -0
- data/lib/rigor/inference/expression_typer/per_element_assemblers.rb +233 -0
- data/lib/rigor/inference/expression_typer/writes.rb +218 -0
- data/lib/rigor/inference/expression_typer.rb +275 -1825
- data/lib/rigor/inference/external_ancestor_resolution.rb +2 -2
- data/lib/rigor/inference/fallback.rb +1 -0
- data/lib/rigor/inference/for_yield_slots.rb +126 -0
- data/lib/rigor/inference/genuine_send.rb +92 -0
- data/lib/rigor/inference/global_write_census.rb +2 -2
- data/lib/rigor/inference/hkt_body.rb +2 -0
- data/lib/rigor/inference/in_effect_refinements/walk.rb +2 -2
- data/lib/rigor/inference/index_write_widening.rb +4 -4
- data/lib/rigor/inference/indexed_narrowing.rb +1 -1
- data/lib/rigor/inference/intervening_ivar_reset.rb +46 -9
- data/lib/rigor/inference/ivar_writer_census.rb +1 -1
- data/lib/rigor/inference/loop_store_sites.rb +239 -0
- data/lib/rigor/inference/macro_block_self_type.rb +4 -3
- data/lib/rigor/inference/method_dispatcher/block_folding.rb +3 -2
- data/lib/rigor/inference/method_dispatcher/call_context.rb +84 -14
- data/lib/rigor/inference/method_dispatcher/composite_receiver.rb +144 -0
- data/lib/rigor/inference/method_dispatcher/constant_folding.rb +7 -5
- data/lib/rigor/inference/method_dispatcher/declared_constructor.rb +1 -1
- data/lib/rigor/inference/method_dispatcher/dependency_source.rb +90 -0
- data/lib/rigor/inference/method_dispatcher/discovered_method.rb +78 -0
- data/lib/rigor/inference/method_dispatcher/file_folding.rb +2 -2
- data/lib/rigor/inference/method_dispatcher/hkt_builtin_return.rb +40 -0
- data/lib/rigor/inference/method_dispatcher/iterator_dispatch.rb +1 -6
- data/lib/rigor/inference/method_dispatcher/literal_string_folding.rb +4 -2
- data/lib/rigor/inference/method_dispatcher/match_data_folding.rb +1 -1
- data/lib/rigor/inference/method_dispatcher/meta_introspection.rb +506 -0
- data/lib/rigor/inference/method_dispatcher/overload_selector.rb +2 -0
- data/lib/rigor/inference/method_dispatcher/plugin_contribution.rb +134 -0
- data/lib/rigor/inference/method_dispatcher/project_patched.rb +134 -0
- data/lib/rigor/inference/method_dispatcher/rbs_dispatch.rb +125 -43
- data/lib/rigor/inference/method_dispatcher/reduce_folding.rb +3 -4
- data/lib/rigor/inference/method_dispatcher/regexp_folding.rb +1 -1
- data/lib/rigor/inference/method_dispatcher/set_folding.rb +1 -1
- data/lib/rigor/inference/method_dispatcher/shape_dispatch.rb +19 -6
- data/lib/rigor/inference/method_dispatcher/singleton_folding.rb +3 -3
- data/lib/rigor/inference/method_dispatcher/singleton_mixin_dispatch.rb +7 -4
- data/lib/rigor/inference/method_dispatcher/static_refinement.rb +106 -0
- data/lib/rigor/inference/method_dispatcher/synthesized_stub.rb +41 -0
- data/lib/rigor/inference/method_dispatcher/synthetic_method_dispatch.rb +133 -0
- data/lib/rigor/inference/method_dispatcher/universal_object_dispatch.rb +2 -1
- data/lib/rigor/inference/method_dispatcher/user_class_fallback.rb +216 -0
- data/lib/rigor/inference/method_dispatcher.rb +175 -1361
- data/lib/rigor/inference/method_parameter_binder.rb +18 -18
- data/lib/rigor/inference/module_function_state.rb +5 -4
- data/lib/rigor/inference/mutation_widening.rb +20 -7
- data/lib/rigor/inference/narrowing/case_literals.rb +58 -0
- data/lib/rigor/inference/narrowing/class_dispatch.rb +302 -0
- data/lib/rigor/inference/narrowing/complements.rb +322 -0
- data/lib/rigor/inference/narrowing/presence_predicates.rb +205 -0
- data/lib/rigor/inference/narrowing/regex_match.rb +499 -0
- data/lib/rigor/inference/narrowing.rb +86 -1269
- data/lib/rigor/inference/object_mixins.rb +2 -2
- data/lib/rigor/inference/opaque_mutation.rb +214 -0
- data/lib/rigor/inference/optimistic_origin.rb +52 -14
- data/lib/rigor/inference/parameter_inference_collector.rb +1 -1
- data/lib/rigor/inference/pre_eval_constants.rb +11 -9
- data/lib/rigor/inference/precision_scanner.rb +27 -2
- data/lib/rigor/inference/project_patched_methods.rb +3 -3
- data/lib/rigor/inference/range_constant.rb +3 -3
- data/lib/rigor/inference/rbs_type_translator.rb +2 -2
- data/lib/rigor/inference/refine_self.rb +8 -7
- data/lib/rigor/inference/refined_dispatch.rb +2 -2
- data/lib/rigor/inference/return_barrier.rb +24 -9
- data/lib/rigor/inference/scope_indexer/alias_def_nodes.rb +311 -0
- data/lib/rigor/inference/scope_indexer/census_scope.rb +47 -0
- data/lib/rigor/inference/scope_indexer/certainty.rb +2 -2
- data/lib/rigor/inference/scope_indexer/class_cvar_census.rb +282 -0
- data/lib/rigor/inference/scope_indexer/class_cvars_collector.rb +12 -5
- data/lib/rigor/inference/scope_indexer/class_declarations.rb +228 -0
- data/lib/rigor/inference/scope_indexer/class_ivar_index.rb +2028 -0
- data/lib/rigor/inference/scope_indexer/constant_ivar_value.rb +4 -3
- data/lib/rigor/inference/scope_indexer/constant_tables.rb +844 -0
- data/lib/rigor/inference/scope_indexer/cvar_hierarchy.rb +159 -0
- data/lib/rigor/inference/scope_indexer/declaration_artifacts.rb +219 -0
- data/lib/rigor/inference/scope_indexer/declaration_signature.rb +212 -0
- data/lib/rigor/inference/scope_indexer/def_nestings_collector.rb +2 -2
- data/lib/rigor/inference/scope_indexer/factory_call_resolver.rb +53 -0
- data/lib/rigor/inference/scope_indexer/literal_receiver_mutations.rb +266 -0
- data/lib/rigor/inference/scope_indexer/member_layouts_collector.rb +8 -7
- data/lib/rigor/inference/scope_indexer/mixin_accumulator.rb +1 -1
- data/lib/rigor/inference/scope_indexer/mixin_effects.rb +470 -0
- data/lib/rigor/inference/scope_indexer/mixin_tables.rb +388 -0
- data/lib/rigor/inference/scope_indexer/mutated_carrier_widening.rb +163 -0
- data/lib/rigor/inference/scope_indexer/mutated_element_census.rb +211 -0
- data/lib/rigor/inference/scope_indexer/node_propagation.rb +520 -0
- data/lib/rigor/inference/scope_indexer/program_globals.rb +154 -0
- data/lib/rigor/inference/scope_indexer/published_constant_cvars.rb +146 -0
- data/lib/rigor/inference/scope_indexer/published_constant_ivars.rb +181 -0
- data/lib/rigor/inference/scope_indexer/shared_walk_tables.rb +823 -0
- data/lib/rigor/inference/scope_indexer/singleton_class_sources.rb +85 -0
- data/lib/rigor/inference/scope_indexer/superclasses_collector.rb +5 -5
- data/lib/rigor/inference/scope_indexer.rb +2657 -9558
- data/lib/rigor/inference/self_call_ivar_writes.rb +22 -3
- data/lib/rigor/inference/set_mutation.rb +2 -2
- data/lib/rigor/inference/singleton_hook_definers.rb +185 -0
- data/lib/rigor/inference/statement_evaluator/def_arguments_and_assertions.rb +365 -0
- data/lib/rigor/inference/statement_evaluator/pattern_bindings.rb +581 -0
- data/lib/rigor/inference/statement_evaluator.rb +201 -1008
- data/lib/rigor/inference/synthetic_method_scanner.rb +0 -3
- data/lib/rigor/language_server/completion_provider.rb +8 -8
- data/lib/rigor/language_server/diagnostic_publisher.rb +6 -7
- data/lib/rigor/language_server/document_symbol_provider.rb +4 -6
- data/lib/rigor/language_server/folding_range_provider.rb +3 -3
- data/lib/rigor/language_server/hover_provider.rb +2 -2
- data/lib/rigor/language_server/loop.rb +2 -2
- data/lib/rigor/language_server/server.rb +3 -2
- data/lib/rigor/language_server/signature_help_provider.rb +7 -9
- data/lib/rigor/lens/document.rb +10 -1
- data/lib/rigor/lens/file_reader.rb +2 -1
- data/lib/rigor/mcp/loop.rb +48 -6
- data/lib/rigor/mcp/server.rb +248 -23
- data/lib/rigor/mcp/skill_catalog.rb +157 -0
- data/lib/rigor/plugin/base.rb +22 -4
- data/lib/rigor/plugin/effect_attribution.rb +1 -1
- data/lib/rigor/plugin/inflector.rb +2 -2
- data/lib/rigor/plugin/io_boundary.rb +1 -1
- data/lib/rigor/plugin/loader.rb +4 -4
- data/lib/rigor/plugin/macro/heredoc_template.rb +4 -3
- data/lib/rigor/plugin/optimistic_return.rb +20 -0
- data/lib/rigor/plugin/registry.rb +2 -2
- data/lib/rigor/plugin/template_unit.rb +4 -2
- data/lib/rigor/plugin/trust_policy.rb +2 -1
- data/lib/rigor/plugin.rb +1 -1
- data/lib/rigor/protection/mutator.rb +8 -9
- data/lib/rigor/rbs_extended/reporter.rb +2 -2
- data/lib/rigor/rbs_extended.rb +2 -2
- data/lib/rigor/reflection/constant_ancestors.rb +1 -1
- data/lib/rigor/reflection/project_method.rb +2 -2
- data/lib/rigor/reflection.rb +4 -4
- data/lib/rigor/scope/discovery_index.rb +15 -10
- data/lib/rigor/scope/resolution_chain.rb +29 -6
- data/lib/rigor/scope.rb +89 -32
- data/lib/rigor/sig_gen/generator.rb +5 -4
- data/lib/rigor/sig_gen/renderer.rb +3 -3
- data/lib/rigor/sig_gen/writer.rb +8 -6
- data/lib/rigor/source/parameter_envelope.rb +1 -1
- data/lib/rigor/triage/catalogue.rb +4 -4
- data/lib/rigor/type/combinator.rb +2 -2
- data/lib/rigor/type/data_instance.rb +2 -2
- data/lib/rigor/type/struct_instance.rb +3 -3
- data/lib/rigor/type_node/generic.rb +2 -1
- data/lib/rigor/type_of_memo.rb +2 -1
- data/lib/rigor/typing_state.rb +3 -2
- data/lib/rigor/version.rb +1 -1
- data/plugins/rigor-actioncable/lib/rigor/plugin/actioncable/analyzer.rb +2 -2
- data/plugins/rigor-actioncable/lib/rigor/plugin/actioncable/channel_discoverer.rb +1 -1
- data/plugins/rigor-actionmailer/lib/rigor/plugin/actionmailer/mailer_discoverer.rb +4 -4
- data/plugins/rigor-actionmailer/lib/rigor/plugin/actionmailer.rb +1 -1
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/controller_discoverer.rb +4 -3
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/effects.rb +7 -5
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/erb_compiler.rb +4 -2
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/render_locals.rb +1 -1
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack/view_assigns.rb +3 -2
- data/plugins/rigor-actionpack/lib/rigor/plugin/actionpack.rb +7 -7
- data/plugins/rigor-activejob/lib/rigor/plugin/activejob/job_discoverer.rb +1 -1
- data/plugins/rigor-activejob/lib/rigor/plugin/activejob.rb +2 -2
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/model_discoverer.rb +9 -8
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/model_index.rb +3 -2
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/schema_parser.rb +15 -7
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/schema_table.rb +10 -3
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord/structure_sql_parser.rb +12 -1
- data/plugins/rigor-activerecord/lib/rigor/plugin/activerecord.rb +20 -5
- data/plugins/rigor-activestorage/lib/rigor/plugin/activestorage/attachment_discoverer.rb +1 -1
- data/plugins/rigor-activestorage/lib/rigor/plugin/activestorage.rb +3 -2
- data/plugins/rigor-activesupport-core-ext/lib/rigor/plugin/activesupport_core_ext/effects.rb +1 -1
- data/plugins/rigor-activesupport-core-ext/lib/rigor/plugin/activesupport_core_ext.rb +8 -7
- data/plugins/rigor-dry-schema/lib/rigor/plugin/dry_schema.rb +1 -1
- data/plugins/rigor-dry-types/lib/rigor/plugin/dry_types/alias_scanner.rb +1 -1
- data/plugins/rigor-dry-types/lib/rigor/plugin/dry_types.rb +6 -7
- data/plugins/rigor-factorybot/lib/rigor/plugin/factorybot/factory_discoverer.rb +3 -2
- data/plugins/rigor-graphql/lib/rigor/plugin/graphql/type_scanner.rb +4 -3
- data/plugins/rigor-hanami/lib/rigor/plugin/hanami.rb +4 -2
- data/plugins/rigor-minitest/lib/rigor/plugin/minitest.rb +1 -1
- data/plugins/rigor-pundit/lib/rigor/plugin/pundit.rb +1 -1
- data/plugins/rigor-rails-i18n/lib/rigor/plugin/rails_i18n/analyzer.rb +5 -3
- data/plugins/rigor-rails-i18n/lib/rigor/plugin/rails_i18n.rb +1 -1
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/devise_routes.rb +4 -5
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/doorkeeper_routes.rb +2 -2
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/helper_discoverer.rb +5 -4
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/helper_table.rb +3 -2
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes/routes_parser.rb +30 -31
- data/plugins/rigor-rails-routes/lib/rigor/plugin/rails_routes.rb +13 -15
- data/plugins/rigor-rbnacl/lib/rigor/plugin/rbnacl.rb +1 -1
- data/plugins/rigor-rspec/lib/rigor/plugin/rspec/let_scope_index.rb +4 -3
- data/plugins/rigor-rspec/lib/rigor/plugin/rspec/matcher_analyzer.rb +16 -13
- data/plugins/rigor-rspec/lib/rigor/plugin/rspec/scope_walker.rb +3 -2
- data/plugins/rigor-shoulda-matchers/lib/rigor/plugin/shoulda_matchers/analyzer.rb +6 -6
- data/plugins/rigor-sidekiq/lib/rigor/plugin/sidekiq/analyzer.rb +3 -3
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/assertion_recognizer.rb +2 -2
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/catalog.rb +3 -2
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/catalog_walker.rb +6 -5
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/sig_parser.rb +2 -2
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/sigil_detector.rb +4 -5
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet/type_translator.rb +1 -1
- data/plugins/rigor-sorbet/lib/rigor/plugin/sorbet.rb +3 -4
- data/sig/rigor/analysis/check_rules/suppression.rbs +9 -0
- data/sig/rigor/analysis/dependency_recorder.rbs +9 -0
- data/sig/rigor/inference.rbs +275 -11
- data/sig/rigor/plugin/base.rbs +14 -5
- data/sig/rigor/plugin/optimistic_return.rbs +16 -0
- data/sig/rigor/scope.rbs +7 -1
- data/sig/rigor/source.rbs +4 -0
- data/skills/rigor-mcp-setup/SKILL.md +20 -6
- data/skills/rigor-plugin-review/SKILL.md +3 -3
- data/skills/rigor-type-oracle/references/01-oracle-commands.md +1 -1
- metadata +90 -3
|
@@ -0,0 +1,576 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "prism"
|
|
4
|
+
require_relative "../../reflection"
|
|
5
|
+
require_relative "../../scope"
|
|
6
|
+
require_relative "../../type"
|
|
7
|
+
require_relative "../../inference/object_mixins"
|
|
8
|
+
require_relative "../../inference/definer_resolution"
|
|
9
|
+
require_relative "rbs_receiver_surface"
|
|
10
|
+
|
|
11
|
+
module Rigor
|
|
12
|
+
module Analysis
|
|
13
|
+
module CheckRules
|
|
14
|
+
# ADR-116 WD1 — the receiver predicates and signature helpers that more than one rule reads: whether a type
|
|
15
|
+
# names a concrete class ({.concrete_class_name}), whether a class's method surface can be enumerated
|
|
16
|
+
# ({.unbounded_receiver_surface?}), how a method is looked up and its signature trusted
|
|
17
|
+
# ({.lookup_method}, {.receiver_signature}, {.trustworthy_signature}), and what the project's own source,
|
|
18
|
+
# `pre_eval:` patches and refinements say about a name.
|
|
19
|
+
#
|
|
20
|
+
# Every method is a module function and none holds state. A rule calls these as `ReceiverPredicates.x`; this
|
|
21
|
+
# module calls no rule back.
|
|
22
|
+
# rubocop:disable-next Metrics/ModuleLength
|
|
23
|
+
module ReceiverPredicates
|
|
24
|
+
module_function
|
|
25
|
+
|
|
26
|
+
# Is a refinement of `call_node`'s method name into `class_name` (or an ancestor) in effect at the call?
|
|
27
|
+
# Issue #1120 asks it for a method the class lacks. The two argument rules ask
|
|
28
|
+
# {#refined_redefinition_in_effect?} instead (issue #1740). Typing the call from the refine body is #1664.
|
|
29
|
+
# Issue #1752 — a class-object receiver (`kind` `:singleton`) is reached by a refinement of any class or module
|
|
30
|
+
# on its lookup: `Class`, `Module`, `Object`, `Kernel`, `BasicObject`, or a module it extends. A refined
|
|
31
|
+
# singleton class (`refine X.singleton_class`) names no constant target, so its rows are class-unknown, which
|
|
32
|
+
# reach every receiver. Issue #1673 — the answer is derived from the file's in-effect refinements
|
|
33
|
+
# ({Inference::InEffectRefinements}), the list the typer reads, with each `using` expanded through its
|
|
34
|
+
# module's includes (issue #1671).
|
|
35
|
+
#
|
|
36
|
+
# ADR-121 WD7 — a module in effect whose refinements Rigor cannot read
|
|
37
|
+
# ({Inference::InEffectRefinements.opaque_module?}: a gem's, one from outside the analysed paths, one with an
|
|
38
|
+
# unreadable `refine`) may refine any class, a class object's included, so the call declines whatever its
|
|
39
|
+
# receiver. Issue #1796.
|
|
40
|
+
def refined_method_in_effect?(class_name, call_node, scope, kind, lexical_sites)
|
|
41
|
+
return false if lexical_sites.nil?
|
|
42
|
+
return true if opaque_refinement_in_effect?(call_node, scope, lexical_sites)
|
|
43
|
+
|
|
44
|
+
modules = Inference::InEffectRefinements.refining_modules(scope, class_name, call_node.name, kind)
|
|
45
|
+
!modules.nil? &&
|
|
46
|
+
lexical_sites.refinements.refinement_active?(call_node.location.start_offset, modules,
|
|
47
|
+
scope.declared_refinements) do |name|
|
|
48
|
+
Inference::InEffectRefinements.activated_modules(scope, name)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Issues #1663, #1740 — the decline `call.wrong-arity` and `call.argument-type-mismatch` ask once a report
|
|
53
|
+
# would fire: a refinement that REDEFINES a method the class already has replaces the signature those rules
|
|
54
|
+
# check against, but Ruby finds a method the receiver's class (or a nearer ancestor) defines before it
|
|
55
|
+
# consults an ancestor's refinement (`refine Object do def center(a, b, c)` leaves `"x".center(1, 2, 3)` an
|
|
56
|
+
# `ArgumentError`). It stands on its own rather than behind {#refined_method_in_effect?}, whose ancestor
|
|
57
|
+
# reach declines `class Inc; def bar(a); include N; end` under `refine N do def bar(a, b, c)` (issue #1797).
|
|
58
|
+
#
|
|
59
|
+
# A call with nothing in effect is checked. Otherwise it reports only from positive knowledge: the list
|
|
60
|
+
# carries no unknown marker and no opaque module, and {Inference::RefinedDispatch::OwnMethod} proves the
|
|
61
|
+
# receiver's own definer answers first. Issue #1752 — a class-object receiver (`kind` `:singleton`) walks its
|
|
62
|
+
# singleton levels: `Integer.sqrt(1, 2)` under `refine Object do def sqrt(a, b)` runs `Integer.sqrt` and raises.
|
|
63
|
+
def refined_redefinition_in_effect?(class_name, call_node, scope, kind, lexical_sites)
|
|
64
|
+
return false if lexical_sites.nil?
|
|
65
|
+
|
|
66
|
+
list = refinement_list_at(call_node, scope, lexical_sites)
|
|
67
|
+
return false if list.empty?
|
|
68
|
+
return true if list.include?(Inference::InEffectRefinements::UNKNOWN)
|
|
69
|
+
return true if opaque_refinement_in_effect?(call_node, scope, lexical_sites)
|
|
70
|
+
|
|
71
|
+
!Inference::RefinedDispatch::OwnMethod.answers?(scope, class_name, call_node.name, list, kind: kind)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# The in-effect list at the call as the typer reads it: the lexical activations, each `using` expanded,
|
|
75
|
+
# then the plugin-declared modules (#1667).
|
|
76
|
+
def refinement_list_at(call_node, scope, lexical_sites)
|
|
77
|
+
query = lexical_sites.refinements
|
|
78
|
+
declared = scope.declared_refinements
|
|
79
|
+
return Inference::InEffectRefinements::EMPTY if query.empty? && declared.empty?
|
|
80
|
+
|
|
81
|
+
query.at(call_node.location.start_offset, declared) do |name|
|
|
82
|
+
Inference::InEffectRefinements.activated_modules(scope, name)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# ADR-121 WD7 — does the call's in-effect list (its lexical activations, each `using` expanded; a
|
|
87
|
+
# plugin-declared module is the plugin's declaration and never opaque) hold an opaque module?
|
|
88
|
+
def opaque_refinement_in_effect?(call_node, scope, lexical_sites)
|
|
89
|
+
query = lexical_sites.refinements
|
|
90
|
+
return false if query.empty?
|
|
91
|
+
|
|
92
|
+
list = Inference::InEffectRefinements.lexical_list(scope, query, call_node.location.start_offset)
|
|
93
|
+
Inference::InEffectRefinements.opaque_in?(scope, list)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Issue #1697 — a module the project mixes into `Object` (a top-level `include M`, or `include M` in
|
|
97
|
+
# `class Object`) gives every object its instance methods, and the RBS lookup above only saw core's
|
|
98
|
+
# `Object`. A class object is an `Object` whatever class it is, so the singleton side always reaches
|
|
99
|
+
# it; the instance side does when the receiver's class descends from `Object`. A mixed-in module
|
|
100
|
+
# whose surface is unknown, or a `module_function` reached only privately, does not count here
|
|
101
|
+
# ({Inference::ObjectMixins.may_define?}).
|
|
102
|
+
def object_mixin_may_define?(receiver_type, class_name, method_name, scope)
|
|
103
|
+
unless receiver_type.is_a?(Type::Singleton) || Inference::ObjectMixins.reaches_object?(scope, class_name)
|
|
104
|
+
return false
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
Inference::ObjectMixins.may_define?(scope, method_name, receiver: :explicit)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Issue #735 — "does the project define this method, on either side, somewhere in its own files".
|
|
111
|
+
# Distinct from {#project_definition_site}, which answers the narrower question the ADR-17 MESSAGE
|
|
112
|
+
# asks (instance-side only, because that is the monkey-patch shape whose `pre_eval:` advice applies).
|
|
113
|
+
# The suppression needs both sides: `def self.available_search_types` in one file and its call in
|
|
114
|
+
# another is the same "second file of my own class" shape as the instance case, and on redmine it is
|
|
115
|
+
# the larger half — modules with class-method surfaces are how that codebase is organised.
|
|
116
|
+
def project_defines_method?(scope, class_name, method_name, kind)
|
|
117
|
+
if kind == :singleton
|
|
118
|
+
# The singleton side has no ancestor walk to ask (#731); it answers for the receiver's own name.
|
|
119
|
+
!scope.user_singleton_def_site_for(class_name, method_name).nil?
|
|
120
|
+
else
|
|
121
|
+
# Through the project's ancestry, not the receiver's name alone: a base class defining a helper
|
|
122
|
+
# its subclasses call is ordinary Ruby, and a sidecar `sig/` that declares the SUBCLASS without
|
|
123
|
+
# that helper was reporting it (`AbstractAdapter#url`, called from `FilesystemAdapter#target`).
|
|
124
|
+
# The def-node walk is what has to answer here — `discovered_methods` deliberately withholds a
|
|
125
|
+
# plain cross-file `def` (`ScopeIndexer#finalize_def_index`), which is exactly this shape.
|
|
126
|
+
!scope.user_def_through_ancestors(class_name, method_name).first.nil?
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def module_mixin_receiver?(receiver_type, scope)
|
|
131
|
+
return false unless receiver_type.is_a?(Type::Nominal)
|
|
132
|
+
return false if scope.environment.nil?
|
|
133
|
+
|
|
134
|
+
scope.environment.rbs_module?(receiver_type.class_name)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# Combined suppression probe for `undefined-method` /
|
|
138
|
+
# `unresolved-toplevel`. Returns true when the method is
|
|
139
|
+
# declared by any project-side contributor the dispatcher
|
|
140
|
+
# already resolves: an in-source `def` / `define_method`
|
|
141
|
+
# (`scope.discovered_method?`) OR an ADR-17 `pre_eval:`
|
|
142
|
+
# monkey-patch (`Environment#project_patched_methods`).
|
|
143
|
+
# Both paths sit at the same dispatcher precedence; the
|
|
144
|
+
# check must hold them together so neither rule fires a
|
|
145
|
+
# false positive.
|
|
146
|
+
#
|
|
147
|
+
# `call_node:` (issue #1708), when given, is the call asking: a private or protected `pre_eval:` patch
|
|
148
|
+
# it may not reach does not count ({#patch_callable?}).
|
|
149
|
+
def source_declared_method?(scope, class_name, method_name, kind, call_node: nil)
|
|
150
|
+
return true if scope.discovered_method?(class_name, method_name, kind)
|
|
151
|
+
|
|
152
|
+
project_patched_method?(scope, class_name, method_name, kind, call_node: call_node)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# Issue #723 — the same question as {#source_declared_method?}, asked through the project's own
|
|
156
|
+
# ANCESTRY rather than the receiver's name alone. A class whose `sig/` declares it without its
|
|
157
|
+
# project superclass typed `:admin_val` under `dump_type` and drew `undefined method 'admin_val'`
|
|
158
|
+
# at the same column of the same run: the probe read a name-keyed table while the typer resolved
|
|
159
|
+
# the call through the class graph.
|
|
160
|
+
#
|
|
161
|
+
# It is deliberately NOT folded into `source_declared_method?`, which every `call.*` rule consults
|
|
162
|
+
# early on its hot path. The walk reads `Scope#superclass_of` / `#includes_of`, and those record an
|
|
163
|
+
# ADR-46 file-level ancestry edge; running it for every call would have made `Widget.new` — a call
|
|
164
|
+
# RBS answers, that never reaches a verdict — record an ancestry dependency on `Widget`'s
|
|
165
|
+
# declaring file, coarsening incremental invalidation for the whole project. Asked HERE, one step
|
|
166
|
+
# before the diagnostic is built, the edge is recorded exactly where the answer depended on it.
|
|
167
|
+
def ancestry_declares_method?(scope, class_name, method_name, kind)
|
|
168
|
+
scope.discovered_method_through_ancestors?(class_name, method_name, kind)
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# ADR-17 § "Inference contract" — consults
|
|
172
|
+
# `Environment#project_patched_methods` so a `def` declared
|
|
173
|
+
# in a `pre_eval:` file suppresses the diagnostic at the
|
|
174
|
+
# same dispatcher precedence the registry holds for type
|
|
175
|
+
# inference (between plugins and dependency-source).
|
|
176
|
+
# Returns false when the environment carries no registry
|
|
177
|
+
# (legacy path) or the lookup misses.
|
|
178
|
+
def project_patched_method?(scope, class_name, method_name, kind, call_node: nil)
|
|
179
|
+
environment = scope.environment
|
|
180
|
+
registry = environment&.project_patched_methods
|
|
181
|
+
return false if registry.nil? || registry.empty?
|
|
182
|
+
|
|
183
|
+
entry = registry.lookup(class_name: class_name.to_s, method_name: method_name.to_sym, kind: kind)
|
|
184
|
+
!entry.nil? && patch_callable?(registry, entry, scope, call_node)
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
# Issue #1708 — {#project_patched_method?} asked through the receiver's ancestors: a `pre_eval:` patch on
|
|
188
|
+
# `Object`, `Numeric` or `Enumerable` gives an `Integer` or `Array` the method. Asked only once the
|
|
189
|
+
# receiver's RBS has come back without the method, so a nearer class's own declaration still decides arity
|
|
190
|
+
# and argument types; {#source_declared_method?} stays exact for the rules that read it for those.
|
|
191
|
+
#
|
|
192
|
+
# `call_node:` as {#source_declared_method?} reads it.
|
|
193
|
+
def project_patched_through_ancestors?(scope, class_name, method_name, kind, call_node: nil)
|
|
194
|
+
environment = scope.environment
|
|
195
|
+
registry = environment&.project_patched_methods
|
|
196
|
+
return false if registry.nil? || registry.empty?
|
|
197
|
+
|
|
198
|
+
entry = registry.lookup_through_ancestors(class_name: class_name.to_s, method_name: method_name.to_sym,
|
|
199
|
+
kind: kind, rbs_loader: environment.rbs_loader)
|
|
200
|
+
!entry.nil? && patch_callable?(registry, entry, scope, call_node)
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
# Issue #1708 — whether `call_node` may reach the patch `entry`: Ruby raises NoMethodError for a private
|
|
204
|
+
# patch called with an explicit receiver other than `self` (`1.kp` on `module Kernel; private def kp`), and
|
|
205
|
+
# for a protected one called from outside its owner's instances. No call node, and a declined verdict (another
|
|
206
|
+
# definer the call may reach, {Inference::ProjectPatchedMethods#callable?}), are the permissive answer.
|
|
207
|
+
def patch_callable?(registry, entry, scope, call_node)
|
|
208
|
+
return true if call_node.nil?
|
|
209
|
+
|
|
210
|
+
receiver = call_node.receiver
|
|
211
|
+
verdict = registry.callable?(entry, explicit: !receiver.nil? && !receiver.is_a?(Prism::SelfNode),
|
|
212
|
+
self_type: scope.self_type, rbs_loader: scope.environment.rbs_loader)
|
|
213
|
+
verdict != false
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
# The receiver shapes whose method surface cannot be enumerated at all, whatever the environment
|
|
217
|
+
# declares: a generic metaclass value, and an instance-side mixin-module type — an instance of some
|
|
218
|
+
# unknown class that includes the module, which may declare the name with any arity of its own
|
|
219
|
+
# (#739's reasoning, applied to the signature rather than to the method's existence).
|
|
220
|
+
#
|
|
221
|
+
# Instance-side only, for #739's reason: `Singleton[M]` on a namespace module is a real, enumerable
|
|
222
|
+
# surface, and `M.helper(1, 2, 3)` must keep firing.
|
|
223
|
+
def unenumerable_receiver_shape?(receiver_type, class_name, scope)
|
|
224
|
+
METACLASS_ARMS.include?(class_name) || module_mixin_receiver?(receiver_type, scope)
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
# Returns a qualified class name for the in-scope check.
|
|
228
|
+
# Nominal / Singleton carry a single-class identity
|
|
229
|
+
# directly. Constant projects to its value's class.
|
|
230
|
+
# Tuple projects to "Array" and HashShape to "Hash" so
|
|
231
|
+
# arity / dispatch checks against the underlying class
|
|
232
|
+
# still apply. Dynamic / Top / Union / Bot do not name a
|
|
233
|
+
# single class and return nil to skip the rule.
|
|
234
|
+
def concrete_class_name(type)
|
|
235
|
+
case type
|
|
236
|
+
when Type::Nominal, Type::Singleton then type.class_name
|
|
237
|
+
when Type::Tuple then "Array"
|
|
238
|
+
when Type::HashShape then "Hash"
|
|
239
|
+
when Type::Constant then constant_class_name(type.value)
|
|
240
|
+
# A refinement IS its base class for method dispatch — its method
|
|
241
|
+
# surface is the base's. Resolve to the base so the call rules
|
|
242
|
+
# (undefined-method / wrong-arity / argument-type-mismatch) reason
|
|
243
|
+
# about it instead of bailing. `Type::Refined` carries string-family
|
|
244
|
+
# refinements (`lowercase-string`, …) over an explicit `.base`;
|
|
245
|
+
# `Type::IntegerRange` carries the bounded-int refinements
|
|
246
|
+
# (`non-negative-int`, `positive-int`, `Integer[1..5]`), every one an
|
|
247
|
+
# Integer; `Type::Difference` (`A - B`) carries the non-empty /
|
|
248
|
+
# non-zero refinements (`non-empty-string` = `String - ""`,
|
|
249
|
+
# `non-empty-array` = `Array - []`, `non-zero-int` = `Integer - 0`)
|
|
250
|
+
# — subtracting values never changes the method surface, so the
|
|
251
|
+
# base (minuend) class dispatches.
|
|
252
|
+
when Type::Refined, Type::Difference then concrete_class_name(type.base)
|
|
253
|
+
when Type::IntegerRange then "Integer"
|
|
254
|
+
when Type::FloatRange then "Float"
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
CONSTANT_CLASSES = {
|
|
259
|
+
Integer => "Integer", Float => "Float", String => "String",
|
|
260
|
+
Symbol => "Symbol", Range => "Range",
|
|
261
|
+
TrueClass => "TrueClass", FalseClass => "FalseClass",
|
|
262
|
+
NilClass => "NilClass"
|
|
263
|
+
}.freeze
|
|
264
|
+
private_constant :CONSTANT_CLASSES
|
|
265
|
+
|
|
266
|
+
# ADR-67 WD6b — true when this call's receiver is *rooted at* a pristine inferred-parameter local (the
|
|
267
|
+
# call-site union seeded at method entry). Every negative in-body rule (`call.undefined-method`,
|
|
268
|
+
# wrong-arity, argument-type-mismatch, possible-nil, visibility) declines on such a receiver: an open
|
|
269
|
+
# call-site set makes the inferred type a *lower bound*, so a diagnostic against it is a false positive
|
|
270
|
+
# by construction (the same reasoning that keeps ADR-67 WD1 non-negotiable at the parameter boundary,
|
|
271
|
+
# carried into the body). No-op on a normal `check` run — `inferred_param?` is false unless the
|
|
272
|
+
# `parameter_inference:` gate seeded the table.
|
|
273
|
+
def inferred_param_receiver?(call_node, scope)
|
|
274
|
+
inferred_param_rooted?(call_node.receiver, scope)
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
# ADR-67 WD6b — the argument-position analogue: true when `arg` is rooted at an inferred-parameter
|
|
278
|
+
# local. The argument-type-mismatch rule declines on it for the same lower-bound reason. `scope` is the
|
|
279
|
+
# call's, and the receiver and any earlier argument run before `arg` and may rebind what a conditional's
|
|
280
|
+
# predicate in it reads (`m((c = false; 1), c ? param : "x")`), so a predicate there is never folded.
|
|
281
|
+
def inferred_param_argument?(arg, scope)
|
|
282
|
+
inferred_param_rooted?(arg, scope, fold: false)
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
# ADR-67 WD6b — see {CheckRules::InferredParamGuard} for the shared root-walk contract.
|
|
286
|
+
def inferred_param_rooted?(node, scope, fold: true)
|
|
287
|
+
InferredParamGuard.rooted?(node, scope, fold: fold)
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
def constant_class_name(value)
|
|
291
|
+
CONSTANT_CLASSES.each { |klass, name| return name if value.is_a?(klass) }
|
|
292
|
+
nil
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
# ADR-26's own counterpart, not a use of it — issue #660 tracks whether this deserves a first-class
|
|
296
|
+
# mechanism of its own rather than living here as a constant. `open_receivers:` (the manifest field,
|
|
297
|
+
# below) only takes effect once a project LOADS the plugin that names it, but a gem overlay
|
|
298
|
+
# (`data/gem_overlay/`, ADR-72) is auto-applied to every project that locks the gem WITHOUT opting
|
|
299
|
+
# into a plugin — there is no manifest in that path for an `open_receivers:` entry to live on. This
|
|
300
|
+
# is that path's counterpart: the class names a BUNDLED overlay declares knowing the declaration is
|
|
301
|
+
# partial, protected independent of any plugin manifest.
|
|
302
|
+
#
|
|
303
|
+
# MEMBERSHIP ALONE is not enough, though: `unbounded_receiver_surface?` (below) also requires the
|
|
304
|
+
# overlay directory that made the entry true to have actually LOADED this run — otherwise a project
|
|
305
|
+
# that never locks the gem, and happens to own a class of the same name itself, would silently lose
|
|
306
|
+
# `call.undefined-method` (and inherited-name `wrong-arity`) on that class, the exact regression this
|
|
307
|
+
# gate exists to avoid (ADR-26 WD1: the protection is active exactly when the RBS it protects is).
|
|
308
|
+
#
|
|
309
|
+
# `ActiveSupport::Duration` is the first (and, as of #632, only) member: it forwards any method its
|
|
310
|
+
# own class doesn't define to the wrapped numeric via `method_missing` (audited against
|
|
311
|
+
# ActiveSupport 8.1.3.1's `lib/active_support/duration.rb` — see
|
|
312
|
+
# `data/gem_overlay/activesupport/core_ext.rbs`'s `ActiveSupport::Duration` comment for the full
|
|
313
|
+
# audit), so declaring even its reader surface makes it RBS-known — and, without this, every member
|
|
314
|
+
# the declaration omits would become a false `call.undefined-method` for every project that locks
|
|
315
|
+
# activesupport, the overwhelming majority of which never opt into the plugin at all.
|
|
316
|
+
# `ActiveSupport::Concern` joined it in #534 item 7. `class_methods do … end` synthesizes a
|
|
317
|
+
# `ClassMethods` constant and `append_features` / `prepend_features` are part of the real surface,
|
|
318
|
+
# none of which the two-line declaration enumerates — and a concern module is the receiver of that
|
|
319
|
+
# surface in every Rails app, so the same argument applies with the same force.
|
|
320
|
+
GEM_OVERLAY_OPEN_RECEIVERS = Set["ActiveSupport::Duration", "ActiveSupport::Concern"].freeze
|
|
321
|
+
private_constant :GEM_OVERLAY_OPEN_RECEIVERS
|
|
322
|
+
|
|
323
|
+
# Issue #1456 — the `data/core_overlay/` twin of {GEM_OVERLAY_OPEN_RECEIVERS}. `OpenStruct` defines each field
|
|
324
|
+
# as a per-instance singleton method and answers the rest through a private `method_missing` (ostruct 0.6), so
|
|
325
|
+
# no signature can enumerate its surface. The only other declaration in the environment is json's add-on
|
|
326
|
+
# reopening (`json_create` / `as_json` / `to_json`), which made the class read as fully declared and every
|
|
327
|
+
# field access a `call.undefined-method`. `data/core_overlay/ostruct.rbs` declares that `method_missing`; since
|
|
328
|
+
# #2792 that alone keeps `call.undefined-method` silent, but the rules below still need the class named. No load
|
|
329
|
+
# gate is needed: the core overlay loads into every environment that has RBS at all, so the list is active
|
|
330
|
+
# whenever the declaration it protects is. Both sides of the class are open, as with
|
|
331
|
+
# {GEM_OVERLAY_OPEN_RECEIVERS}, and an inherited Object / Kernel signature stops deciding `call.wrong-arity`
|
|
332
|
+
# and `call.argument-type-mismatch` ({#unauthoritative_inherited_signature?}): lost true positives,
|
|
333
|
+
# accepted. The general rule — a class declared only by another library's partial reopening — is #1978, not
|
|
334
|
+
# this list.
|
|
335
|
+
CORE_OVERLAY_OPEN_RECEIVERS = Set["OpenStruct"].freeze
|
|
336
|
+
private_constant :CORE_OVERLAY_OPEN_RECEIVERS
|
|
337
|
+
|
|
338
|
+
# True when the receiver class responds beyond an enumerable
|
|
339
|
+
# RBS method table, so proving a call "undefined" against it is
|
|
340
|
+
# unsound: a plugin-declared open receiver, a Rigor-bundled-
|
|
341
|
+
# overlay open receiver ({GEM_OVERLAY_OPEN_RECEIVERS}) whose
|
|
342
|
+
# bundled directory this run actually loaded, a core-overlay
|
|
343
|
+
# open receiver ({CORE_OVERLAY_OPEN_RECEIVERS}), or a
|
|
344
|
+
# Rigor-synthesized stub type (see `RbsLoader#synthesized_type_names`),
|
|
345
|
+
# or a project-only reopen of a Ruby library class whose own RBS
|
|
346
|
+
# did not load ({#ruby_library_reopen?}).
|
|
347
|
+
def unbounded_receiver_surface?(class_name, scope)
|
|
348
|
+
bare_name = class_name.to_s.sub(/\A::/, "")
|
|
349
|
+
open_receiver?(class_name, scope) || synthesized_stub_receiver?(class_name, scope) ||
|
|
350
|
+
CORE_OVERLAY_OPEN_RECEIVERS.include?(bare_name) ||
|
|
351
|
+
(GEM_OVERLAY_OPEN_RECEIVERS.include?(bare_name) && gem_overlay_loaded?(scope)) ||
|
|
352
|
+
ruby_library_reopen?(class_name, scope)
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
# Issue #2174 — `class Matrix` reopened with one `#:`-annotated method, and no `matrix` signatures
|
|
356
|
+
# loaded, gives Matrix a declaration holding only that method ({RbsLoader#ruby_library_reopen?}).
|
|
357
|
+
# `Matrix.identity(2)` is correct Ruby, so the class's surface is treated as open: `call.undefined-method`
|
|
358
|
+
# declines on it, and a signature it only inherits (`Object#initialize` for `Matrix.new(rows)`) stops
|
|
359
|
+
# deciding arity and argument types. Methods the project's own declaration lists stay checked.
|
|
360
|
+
def ruby_library_reopen?(class_name, scope)
|
|
361
|
+
loader = scope.environment&.rbs_loader
|
|
362
|
+
return false if loader.nil? || !loader.respond_to?(:ruby_library_reopen?)
|
|
363
|
+
|
|
364
|
+
loader.ruby_library_reopen?(class_name)
|
|
365
|
+
end
|
|
366
|
+
|
|
367
|
+
# ADR-26 — whether a loaded plugin declares `class_name` "open" (manifest `open_receivers:`): it responds
|
|
368
|
+
# beyond its RBS surface.
|
|
369
|
+
def open_receiver?(class_name, scope)
|
|
370
|
+
registry = scope.environment&.plugin_registry
|
|
371
|
+
return false if registry.nil?
|
|
372
|
+
|
|
373
|
+
registry.open_receiver?(class_name)
|
|
374
|
+
end
|
|
375
|
+
|
|
376
|
+
# Whether THIS run's RBS environment actually includes Rigor's OWN partial declaration of
|
|
377
|
+
# ACTIVESUPPORT — {GEM_OVERLAY_OPEN_RECEIVERS} membership alone must not grant the exemption (see
|
|
378
|
+
# that constant's comment), and both members of that list are `ActiveSupport` classes, so the gate
|
|
379
|
+
# asks for the activesupport overlay specifically. Issue #2857 added a SECOND bundled overlay
|
|
380
|
+
# (`addressable`, eligible under `:rbs_collection` coverage), and a collection project can load it
|
|
381
|
+
# while the activesupport overlay stays unloaded — keying on "any `data/gem_overlay/` directory"
|
|
382
|
+
# would then silence `ActiveSupport::Duration#bar`, the ADR-26 false negative this gate exists to
|
|
383
|
+
# prevent.
|
|
384
|
+
#
|
|
385
|
+
# `RbsLoader#signature_paths` is the same list `Environment.for_project` builds from
|
|
386
|
+
# `resolved_paths + plugin_sig_paths + gem_sig_paths + collection_paths + overlay_paths`, and
|
|
387
|
+
# two of its members can carry the activesupport declaration:
|
|
388
|
+
#
|
|
389
|
+
# - `data/gem_overlay/activesupport/` itself — a member if and only if `gem_overlay_paths` picked
|
|
390
|
+
# it (the gem is locked, its coverage source admits the overlay — `:missing` for activesupport —
|
|
391
|
+
# and its plugin twin is NOT reachable, ADR-72). {RbsLoader.gem_overlay_sig_paths} rebuilds the
|
|
392
|
+
# exact Pathname `for_project` appended, so a plain `include?` is the test: no other signature
|
|
393
|
+
# source can occupy that path;
|
|
394
|
+
# - the bundled activesupport plugin twin's own `sig/`, when a project wires it through
|
|
395
|
+
# `signature_paths:` instead of `plugins:`. Before #672 that route loaded BOTH halves and
|
|
396
|
+
# `Duration` collapsed outright, so nothing fired and nothing needed protecting; now the overlay
|
|
397
|
+
# stands down and the twin's declaration is the one that loads — with no manifest behind it, so
|
|
398
|
+
# `open_receiver?` above stays false and this is the only thing standing between a real
|
|
399
|
+
# `Duration` receiver and a false `call.undefined-method` on every member the declaration
|
|
400
|
+
# omits. {RbsLoader.gem_overlay_twin_signatures_loaded?} enumerates `GEM_OVERLAY_PLUGIN_IDS`'
|
|
401
|
+
# values, which today is only the activesupport twin; a second overlay twin would need the same
|
|
402
|
+
# per-gem keying this method now applies to the directory arm.
|
|
403
|
+
#
|
|
404
|
+
# When the PLUGIN itself is loaded the first arm goes false (the overlay stands down) and the
|
|
405
|
+
# second goes true — its `sig/` rides in as a plugin signature path — but nothing here decides
|
|
406
|
+
# that case: `open_receiver?`'s manifest-driven check short-circuits above it. The two answers
|
|
407
|
+
# agree, which is the point; this predicate asks only whether the Rigor-authored activesupport
|
|
408
|
+
# declaration is in the environment, never how the project asked for it.
|
|
409
|
+
#
|
|
410
|
+
# The two arms are asked in that order, over the WHOLE list each time, rather than interleaved
|
|
411
|
+
# per path: the overlay arm is a Pathname comparison (plus the two `File.directory?` probes
|
|
412
|
+
# {RbsLoader.gem_overlay_sig_paths} needs to rebuild the path) and the twin arm canonicalises
|
|
413
|
+
# paths on the filesystem, so an overlay-only run pays the cheaper arm first.
|
|
414
|
+
def gem_overlay_loaded?(scope)
|
|
415
|
+
loader = scope.environment&.rbs_loader
|
|
416
|
+
return false if loader.nil? || !loader.respond_to?(:signature_paths)
|
|
417
|
+
|
|
418
|
+
paths = loader.signature_paths
|
|
419
|
+
activesupport_overlay = Rigor::Environment::RbsLoader.gem_overlay_sig_paths(["activesupport"])
|
|
420
|
+
paths.any? { |path| activesupport_overlay.include?(path) } ||
|
|
421
|
+
Rigor::Environment::RbsLoader.gem_overlay_twin_signatures_loaded?(paths)
|
|
422
|
+
end
|
|
423
|
+
|
|
424
|
+
# Issue #653 — true when a plugin's `dynamic_return` supplied the return type for THIS call node
|
|
425
|
+
# (recorded by `MethodDispatcher` on `Scope#plugin_typed_calls` during the typing pass, exactly the
|
|
426
|
+
# way `Scope#void_origins` is recorded and consumed).
|
|
427
|
+
#
|
|
428
|
+
# Why the rule declines. The plugin tier sits ABOVE `RbsDispatch` in `MethodDispatcher#resolve_site`, so
|
|
429
|
+
# a plugin answer means the RBS never dispatched the call: the type at the site is the plugin's.
|
|
430
|
+
# Reading that same receiver's RBS afterwards to prove the call undefined puts the two subsystems in
|
|
431
|
+
# direct contradiction on one line of one run — the plugin says `Rails.logger` is an
|
|
432
|
+
# `ActiveSupport::BroadcastLogger`, the rule says `logger` does not exist. Under ADR-5 a
|
|
433
|
+
# partially-declared receiver is not a closed world, and incompleteness is exactly what a plugin is
|
|
434
|
+
# loaded to cover, so the plugin's answer is the honest one. Without this, adding a four-line
|
|
435
|
+
# partial `sig/` for a class a plugin already covered turned every covered call site into an error
|
|
436
|
+
# — writing more RBS made a project's diagnostics worse.
|
|
437
|
+
#
|
|
438
|
+
# Deliberately NOT scoped to "the RBS is silent about this method": the precedence recorded here is
|
|
439
|
+
# the dispatcher's own, and the dispatcher does not consult the RBS before letting a plugin answer.
|
|
440
|
+
# For THIS rule the two readings coincide anyway — a method the RBS declares is found by
|
|
441
|
+
# `lookup_method` below and never reaches the diagnostic — so the broader statement costs no
|
|
442
|
+
# diagnostic and keeps the contract stated in one direction. `docs/internal-spec/plugin.md` §
|
|
443
|
+
# "Return-type and narrowing contributions" is where it binds.
|
|
444
|
+
#
|
|
445
|
+
# Unlike {#unbounded_receiver_surface?} this is per CALL SITE, not per receiver class: a plugin
|
|
446
|
+
# answering `Rails.logger` exempts that call and nothing else, so `Rails.no_such_reader` on the same
|
|
447
|
+
# receiver still fires.
|
|
448
|
+
def plugin_typed_call?(call_node, scope)
|
|
449
|
+
scope.plugin_typed_call?(call_node)
|
|
450
|
+
end
|
|
451
|
+
|
|
452
|
+
def synthesized_stub_receiver?(class_name, scope)
|
|
453
|
+
loader = scope.environment&.rbs_loader
|
|
454
|
+
return false if loader.nil? || !loader.respond_to?(:synthesized_type_names)
|
|
455
|
+
|
|
456
|
+
loader.synthesized_type_names.include?(class_name.to_s.sub(/\A::/, ""))
|
|
457
|
+
end
|
|
458
|
+
|
|
459
|
+
# ADR-26 — the SIGNATURE half of the open-receiver policy. `call.undefined-method` already declines
|
|
460
|
+
# on an unbounded surface: a plugin vouches that the class answers names its RBS cannot enumerate
|
|
461
|
+
# (an `ActiveRecord::Relation` delegates every user-declared `scope` to its model). The rules that
|
|
462
|
+
# read a RESOLVED SIGNATURE — wrong-arity and argument-type-mismatch — must decline on the same
|
|
463
|
+
# ground, but only where the name resolved through an ANCESTOR rather than the open class itself.
|
|
464
|
+
#
|
|
465
|
+
# The failure it closes: `Issue.visible.open` is a declared scope taking `*args`, but `open` is also
|
|
466
|
+
# `Kernel#open`, so resolution walks the Relation's ancestry, finds the IO opener and checks the
|
|
467
|
+
# call against `(String, ...)` — `wrong number of arguments (given 0, expected 1..3)` on correct
|
|
468
|
+
# code, plus `argument type mismatch: expected String, got false` on `open(false)`. The collision
|
|
469
|
+
# set is every Object/Kernel name, so any project whose scope is called `open`, `select`, `test`,
|
|
470
|
+
# `format`, `p`, `system`, … inherits the error the moment the first hop types. That is a wrong
|
|
471
|
+
# signature applied to a method the receiver does not actually run — not a strict reading of a real
|
|
472
|
+
# one — and it fires on code that works.
|
|
473
|
+
#
|
|
474
|
+
# A method the open class DECLARES stays checked: `Relation#limit` is in the plugin's own bundled
|
|
475
|
+
# RBS, so `relation.limit` with no arguments still fires. The suppression is therefore bounded to
|
|
476
|
+
# names the open class inherited, where the resolution was never authoritative to begin with.
|
|
477
|
+
# The RBS method definition this call may be validated against, or nil when there is none worth
|
|
478
|
+
# trusting: the lookup found nothing, it returned {#lookup_method}'s defensive `true` sentinel, or
|
|
479
|
+
# the name is one an open receiver INHERITED rather than declared. Shared by the two rules that read
|
|
480
|
+
# a resolved signature — `call.wrong-arity` and `call.argument-type-mismatch` — so they cannot drift
|
|
481
|
+
# on which signatures are authoritative.
|
|
482
|
+
def trustworthy_signature(receiver_type, class_name, call_node, scope)
|
|
483
|
+
method_def = lookup_method(receiver_type, class_name, call_node.name, scope)
|
|
484
|
+
return nil if method_def.nil? || method_def == true
|
|
485
|
+
return nil if unauthoritative_inherited_signature?(class_name, method_def, scope)
|
|
486
|
+
|
|
487
|
+
method_def
|
|
488
|
+
end
|
|
489
|
+
|
|
490
|
+
# Issue #2786 — {#trustworthy_signature} on the call's receiver as {CallFacts} types it, resolved once per
|
|
491
|
+
# call node: `call.wrong-arity` and `call.argument-type-mismatch` both ask it with that receiver type and its
|
|
492
|
+
# concrete class.
|
|
493
|
+
def receiver_signature(facts)
|
|
494
|
+
facts.receiver_signature do
|
|
495
|
+
receiver_type = facts.receiver_type
|
|
496
|
+
trustworthy_signature(receiver_type, concrete_class_name(receiver_type), facts.call_node, facts.scope)
|
|
497
|
+
end
|
|
498
|
+
end
|
|
499
|
+
|
|
500
|
+
def unauthoritative_inherited_signature?(class_name, method_def, scope)
|
|
501
|
+
return false unless unbounded_receiver_surface?(class_name, scope)
|
|
502
|
+
return true unless method_def.respond_to?(:defined_in)
|
|
503
|
+
|
|
504
|
+
defined_in = method_def.defined_in
|
|
505
|
+
return true if defined_in.nil?
|
|
506
|
+
|
|
507
|
+
strip_root(defined_in.to_s) != strip_root(class_name)
|
|
508
|
+
end
|
|
509
|
+
|
|
510
|
+
def strip_root(name) = name.to_s.sub(/\A::/, "")
|
|
511
|
+
|
|
512
|
+
def definition_available?(receiver_type, class_name, scope)
|
|
513
|
+
if receiver_type.is_a?(Type::Singleton)
|
|
514
|
+
!Rigor::Reflection.singleton_definition(class_name, scope: scope).nil?
|
|
515
|
+
else
|
|
516
|
+
!Rigor::Reflection.instance_definition(class_name, scope: scope).nil?
|
|
517
|
+
end
|
|
518
|
+
end
|
|
519
|
+
|
|
520
|
+
def lookup_method(receiver_type, class_name, method_name, scope)
|
|
521
|
+
if receiver_type.is_a?(Type::Singleton)
|
|
522
|
+
Rigor::Reflection.singleton_method_definition(class_name, method_name, scope: scope)
|
|
523
|
+
else
|
|
524
|
+
Rigor::Reflection.instance_method_definition(class_name, method_name, scope: scope)
|
|
525
|
+
end
|
|
526
|
+
rescue StandardError
|
|
527
|
+
# The Reflection facade catches loader exceptions and
|
|
528
|
+
# returns nil. The wrapper here treats failures as
|
|
529
|
+
# "method exists" so we do NOT emit a false positive
|
|
530
|
+
# when our knowledge of the receiver class is
|
|
531
|
+
# structurally incomplete (Reflection's own rescue
|
|
532
|
+
# already returns nil; this catch is a defensive
|
|
533
|
+
# double-net for any future call shape that might
|
|
534
|
+
# raise).
|
|
535
|
+
true
|
|
536
|
+
end
|
|
537
|
+
|
|
538
|
+
def nil_member?(member)
|
|
539
|
+
(member.is_a?(Type::Constant) && member.value.nil?) ||
|
|
540
|
+
(member.is_a?(Type::Nominal) && member.class_name == "NilClass")
|
|
541
|
+
end
|
|
542
|
+
|
|
543
|
+
def method_present_anywhere?(member, method_name, scope)
|
|
544
|
+
class_name = concrete_class_name(member)
|
|
545
|
+
return true if class_name.nil? # Dynamic / Top / Bot — be permissive.
|
|
546
|
+
return true if scope.discovered_method?(class_name, method_name, :instance)
|
|
547
|
+
return true unless Rigor::Reflection.rbs_class_known?(class_name, scope: scope)
|
|
548
|
+
return true unless definition_available?(member, class_name, scope)
|
|
549
|
+
return true if lookup_method(member, class_name, method_name, scope)
|
|
550
|
+
return true if project_patched_through_ancestors?(scope, class_name, method_name, :instance)
|
|
551
|
+
|
|
552
|
+
# Issue #723 — the arm's own RBS does not have it; its project ancestry still might. Late, for
|
|
553
|
+
# the reason {#ancestry_declares_method?} carries: this is the probe that walks the class graph.
|
|
554
|
+
return true if ancestry_declares_method?(scope, class_name, method_name, :instance)
|
|
555
|
+
|
|
556
|
+
object_mixin_may_define?(member, class_name, method_name, scope)
|
|
557
|
+
end
|
|
558
|
+
|
|
559
|
+
# An arm that makes a sound "undefined on every arm" verdict impossible: a non-class surface
|
|
560
|
+
# (Dynamic / Top / Bot), a singleton (slice 1 reasons about instance arms only), the generic
|
|
561
|
+
# metaclass `Class` / `Module` (a value typed as one is *some* class/module object whose singleton
|
|
562
|
+
# methods cannot be enumerated from the metaclass — e.g. `plugin_class : Class` really holds a
|
|
563
|
+
# `Plugin` subclass with `.manifest`), an unbounded receiver (ADR-26 open class or a synthesized
|
|
564
|
+
# stub), or a module mixin whose Object-inherited methods the per-arm lookup would miss.
|
|
565
|
+
METACLASS_ARMS = %w[Class Module].to_set.freeze
|
|
566
|
+
private_constant :METACLASS_ARMS
|
|
567
|
+
|
|
568
|
+
# Whether `class_name` is the generic metaclass `Class` / `Module`; {UndefinedMethod} asks it rather than
|
|
569
|
+
# reading {METACLASS_ARMS}, which stays private.
|
|
570
|
+
def metaclass_arm?(class_name)
|
|
571
|
+
METACLASS_ARMS.include?(class_name)
|
|
572
|
+
end
|
|
573
|
+
end
|
|
574
|
+
end
|
|
575
|
+
end
|
|
576
|
+
end
|