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
|
@@ -43,8 +43,8 @@ module Rigor
|
|
|
43
43
|
@receiver_type ||= @scope.type_of(@call_node.receiver)
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
# The signature `
|
|
47
|
-
# is remembered too. A block that raises leaves it unresolved, so the next ask raises as it did before.
|
|
46
|
+
# The signature `ReceiverPredicates.receiver_signature` resolves, its block run on the first ask only. A nil
|
|
47
|
+
# answer is remembered too. A block that raises leaves it unresolved, so the next ask raises as it did before.
|
|
48
48
|
def receiver_signature
|
|
49
49
|
return @receiver_signature if @receiver_signature_resolved
|
|
50
50
|
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
require "prism"
|
|
4
4
|
|
|
5
5
|
require_relative "../../source/node_children"
|
|
6
|
+
require_relative "../diagnostic"
|
|
7
|
+
require_relative "rule_ids"
|
|
6
8
|
|
|
7
9
|
module Rigor
|
|
8
10
|
module Analysis
|
|
@@ -30,7 +32,7 @@ module Rigor
|
|
|
30
32
|
class DeadAssignmentCollector
|
|
31
33
|
# ADR-53 Track B — the node classes the shared {RuleWalk} dispatches to this collector. The legacy
|
|
32
34
|
# walk visits EVERY `DefNode` (it descends into all of them, nested defs included, processing each
|
|
33
|
-
# separately — `
|
|
35
|
+
# separately — `gather_write_nodes` stops at nested defs so an outer def never reports an inner def's writes),
|
|
34
36
|
# so the collector needs no context gate: it fires at every `def` the shared full DFS reaches,
|
|
35
37
|
# exactly like the legacy walk.
|
|
36
38
|
NODE_CLASSES = [Prism::DefNode].freeze
|
|
@@ -61,6 +63,33 @@ module Rigor
|
|
|
61
63
|
@results.freeze
|
|
62
64
|
end
|
|
63
65
|
|
|
66
|
+
# ADR-116 WD1 — the message builder for this collector's results, moved here from `CheckRules`.
|
|
67
|
+
# {.diagnostics} is called by `CheckRules.diagnose` through its collector table; the rest is private to it.
|
|
68
|
+
|
|
69
|
+
# v0.1.2 — `flow.dead-assignment`. Walks every `DefNode`
|
|
70
|
+
# body and emits a diagnostic for each plain
|
|
71
|
+
# `LocalVariableWriteNode` whose target name is never
|
|
72
|
+
# read in the same body. The
|
|
73
|
+
# `Analysis::CheckRules::DeadAssignmentCollector` describes
|
|
74
|
+
# the conservative envelope.
|
|
75
|
+
def self.diagnostics(path, dead_assignments)
|
|
76
|
+
dead_assignments.map do |result|
|
|
77
|
+
build_dead_assignment_diagnostic(path, result[:write_node], result[:def_node])
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def self.build_dead_assignment_diagnostic(path, write_node, def_node)
|
|
82
|
+
Diagnostic.from_name_loc(
|
|
83
|
+
write_node,
|
|
84
|
+
rule: RULE_DEAD_ASSIGNMENT,
|
|
85
|
+
path: path,
|
|
86
|
+
message: "local `#{write_node.name}' assigned in `#{def_node.name}' but never read",
|
|
87
|
+
severity: :warning
|
|
88
|
+
)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
private_class_method :build_dead_assignment_diagnostic
|
|
92
|
+
|
|
64
93
|
private
|
|
65
94
|
|
|
66
95
|
def walk_for_def_nodes(node)
|
|
@@ -27,10 +27,9 @@ module Rigor
|
|
|
27
27
|
# A branch join keeps the mark when both arms stamp it: `if c then r = @count else r = @count end` stamps
|
|
28
28
|
# `(:local, :r)` on each arm, and `join_declaration_sourced` INTERSECTS, so the mark survives. Only an
|
|
29
29
|
# *asymmetric* join drops it, by that intersection rather than by reaching `with_local`. The normative
|
|
30
|
-
# statement — establishment, drop, join and the full list of
|
|
31
|
-
#
|
|
32
|
-
#
|
|
33
|
-
# comment subordinate to it.
|
|
30
|
+
# statement — establishment, drop, join and the full list of unmarked shapes, each verified against the
|
|
31
|
+
# implementation — is `docs/internal-spec/inference-engine.md` § "Declaration-sourced provenance mark (ADR-58)";
|
|
32
|
+
# keep this comment subordinate to it.
|
|
34
33
|
#
|
|
35
34
|
# So `marked?` matches exactly the node shapes the scope actually models and invents no propagation of its
|
|
36
35
|
# own; anything flow-live keeps firing.
|
|
@@ -61,7 +60,7 @@ module Rigor
|
|
|
61
60
|
|
|
62
61
|
# Issue #2656 — true when `node` reads a local a class guard narrowed from a `Dynamic` value
|
|
63
62
|
# ({Scope#with_gradual_narrowing_mark}). `call.argument-type-mismatch` judges such an argument by its class
|
|
64
|
-
# rather than against the parameter's literals (`
|
|
63
|
+
# rather than against the parameter's literals (`ArgumentType.gradual_narrowing_accepted?`); the other rules
|
|
65
64
|
# read the narrowed `Nominal` as before.
|
|
66
65
|
def gradual_narrowed?(node, scope)
|
|
67
66
|
node.is_a?(Prism::LocalVariableReadNode) && scope.gradual_narrowing?(node.name)
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
require "prism"
|
|
4
4
|
|
|
5
5
|
require_relative "../../source/node_children"
|
|
6
|
+
require_relative "../diagnostic"
|
|
7
|
+
require_relative "rule_ids"
|
|
6
8
|
|
|
7
9
|
module Rigor
|
|
8
10
|
module Analysis
|
|
@@ -64,6 +66,38 @@ module Rigor
|
|
|
64
66
|
@results.freeze
|
|
65
67
|
end
|
|
66
68
|
|
|
69
|
+
# ADR-116 WD1 — the message builder for this collector's results, moved here from `CheckRules`.
|
|
70
|
+
# {.diagnostics} is called by `CheckRules.diagnose` through its collector table; the rest is private to it.
|
|
71
|
+
|
|
72
|
+
# v0.3.0 — `flow.duplicate-hash-key`. Emits a diagnostic for each LATER occurrence of a repeated
|
|
73
|
+
# LITERAL key within one Hash literal (braced or bare-kwargs) — Ruby keeps the last entry silently
|
|
74
|
+
# at runtime, so the earlier value is dead. The
|
|
75
|
+
# `Analysis::CheckRules::DuplicateHashKeyCollector` describes the value-pinned-literal-only
|
|
76
|
+
# envelope (symbols / plain strings / integers / floats / true / false / nil; never
|
|
77
|
+
# cross-kind, never interpolation / constants / calls / splats).
|
|
78
|
+
def self.diagnostics(path, duplicate_keys)
|
|
79
|
+
duplicate_keys.map do |result|
|
|
80
|
+
build_duplicate_hash_key_diagnostic(path, result)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# The diagnostic points at the LATER occurrence (the entry that wins at runtime) and names the
|
|
85
|
+
# first occurrence's line, so the fix — delete or rename one of the two — is visible from the
|
|
86
|
+
# message alone.
|
|
87
|
+
def self.build_duplicate_hash_key_diagnostic(path, result)
|
|
88
|
+
first_line = result[:first_key_node].location.start_line
|
|
89
|
+
Diagnostic.from_node(
|
|
90
|
+
result[:key_node],
|
|
91
|
+
rule: RULE_DUPLICATE_HASH_KEY,
|
|
92
|
+
path: path,
|
|
93
|
+
message: "duplicate hash key `#{result[:key_label]}' in the same literal; this entry " \
|
|
94
|
+
"overwrites the value first set at line #{first_line}",
|
|
95
|
+
severity: :warning
|
|
96
|
+
)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
private_class_method :build_duplicate_hash_key_diagnostic
|
|
100
|
+
|
|
67
101
|
private
|
|
68
102
|
|
|
69
103
|
def walk_for_hash_nodes(node)
|
|
@@ -3,10 +3,15 @@
|
|
|
3
3
|
require "prism"
|
|
4
4
|
|
|
5
5
|
require_relative "rule_walk"
|
|
6
|
+
require_relative "override_visibility"
|
|
6
7
|
require_relative "../../scope/resolution_chain"
|
|
7
8
|
require_relative "../../source/constant_path"
|
|
8
9
|
require_relative "../../source/node_children"
|
|
9
10
|
require_relative "../../inference/census_foreign_block"
|
|
11
|
+
require_relative "../../inference/acceptance"
|
|
12
|
+
require_relative "../diagnostic"
|
|
13
|
+
require_relative "receiver_predicates"
|
|
14
|
+
require_relative "rule_ids"
|
|
10
15
|
|
|
11
16
|
module Rigor
|
|
12
17
|
module Analysis
|
|
@@ -14,8 +19,8 @@ module Rigor
|
|
|
14
19
|
# Walks a parse tree and collects every `Prism::InstanceVariableWriteNode` inside an instance method
|
|
15
20
|
# body of a `Prism::ClassNode` / `Prism::ModuleNode`, grouped by (class qualified name, ivar name).
|
|
16
21
|
#
|
|
17
|
-
# The collector is the read-side companion to `Inference::ScopeIndexer
|
|
18
|
-
# indexer unions the rvalue types into a single per-ivar carrier; this collector preserves the per-write
|
|
22
|
+
# The collector is the read-side companion to `Inference::ScopeIndexer::ClassIvarIndex.build_class_ivar_index`.
|
|
23
|
+
# The indexer unions the rvalue types into a single per-ivar carrier; this collector preserves the per-write
|
|
19
24
|
# list so the `def.ivar-write-mismatch` rule can compare each write's concrete class against the first.
|
|
20
25
|
#
|
|
21
26
|
# Skipped on purpose:
|
|
@@ -28,7 +33,7 @@ module Rigor
|
|
|
28
33
|
# - Class-body ivar writes outside any def — the `Module#@var` surface is a separate slice the engine
|
|
29
34
|
# doesn't yet model.
|
|
30
35
|
# - Nested classes / modules / defs inside a method body are barriers, mirroring the indexer's
|
|
31
|
-
# `IVAR_BARRIER_NODES` policy.
|
|
36
|
+
# `ClassIvarIndex::IVAR_BARRIER_NODES` policy.
|
|
32
37
|
# - Issue #2943: a write directly in a block or `class << obj` body whose `self` is provably not an instance
|
|
33
38
|
# of the class (`Other.new.instance_eval { @r = 1 }`), by the class-ivar census's rule
|
|
34
39
|
# ({Inference::CensusForeignBlock}).
|
|
@@ -93,6 +98,128 @@ module Rigor
|
|
|
93
98
|
end.freeze
|
|
94
99
|
end
|
|
95
100
|
|
|
101
|
+
# ADR-116 WD1 — the message builder for this collector's results, moved here from `CheckRules`.
|
|
102
|
+
# {.diagnostics} is called by `CheckRules.diagnose` through its collector table; the rest is private to it.
|
|
103
|
+
|
|
104
|
+
# v0.1.2 — `def.ivar-write-mismatch`. Walks every
|
|
105
|
+
# ClassNode / ModuleNode body, gathers per-class ivar
|
|
106
|
+
# writes with their rvalue types, and emits a diagnostic
|
|
107
|
+
# when a later write's concrete class disagrees with the
|
|
108
|
+
# first write's. The first write per (class, ivar) is
|
|
109
|
+
# treated as the "declared" type; subsequent writes that
|
|
110
|
+
# land on a different concrete class trigger.
|
|
111
|
+
#
|
|
112
|
+
# Conservative envelope:
|
|
113
|
+
# - Only fires when both the first and the offending
|
|
114
|
+
# write resolve to a `concrete_class_name` (Nominal /
|
|
115
|
+
# Singleton / Constant / Tuple → "Array" / HashShape →
|
|
116
|
+
# "Hash"). Unions / Dynamic / IntegerRange / shape-
|
|
117
|
+
# varied carriers fall through.
|
|
118
|
+
# - `NilClass` is an intentional widening idiom (`@x =
|
|
119
|
+
# "value"` then later `@x = nil` to "clear") — skipped.
|
|
120
|
+
# - Singleton-method (`def self.foo`) bodies are skipped.
|
|
121
|
+
# Class-level ivars (`@x = 1` outside any def, in the
|
|
122
|
+
# class body) are also skipped — they're a separate
|
|
123
|
+
# surface (`Module#@var`) the engine doesn't yet model.
|
|
124
|
+
# - A divergence the class's RBS declaration admits is withheld: when the ivar is declared (`@x: T`,
|
|
125
|
+
# or the slot an `attr_*` member implies) and that type accepts both the first write and the
|
|
126
|
+
# later one, the union is the author's intent. The declaration only silences here; checking
|
|
127
|
+
# writes against it is #1406.
|
|
128
|
+
def self.diagnostics(path, ivar_writes)
|
|
129
|
+
ivar_writes.flat_map do |class_name, writes_by_ivar|
|
|
130
|
+
writes_by_ivar.flat_map do |ivar_name, writes|
|
|
131
|
+
ivar_mismatch_diagnostics_for(path, class_name, ivar_name, writes)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def self.ivar_mismatch_diagnostics_for(path, class_name, ivar_name, writes)
|
|
137
|
+
return [] if writes.size < 2
|
|
138
|
+
|
|
139
|
+
# Skip past leading `NilClass` writes when establishing
|
|
140
|
+
# the canonical type. The common nullable-slot idiom
|
|
141
|
+
# (`@x = nil` placeholder in `initialize` / a default
|
|
142
|
+
# state slot, then `@x = :foo` on first concrete state)
|
|
143
|
+
# would otherwise fire a false positive on every
|
|
144
|
+
# concrete write because `first_class` was `NilClass`
|
|
145
|
+
# and every subsequent `Symbol` / `String` / `Hash`
|
|
146
|
+
# write triggered the divergence rule. The first
|
|
147
|
+
# concrete (non-nil) write is the canonical type;
|
|
148
|
+
# additional `NilClass` writes are still tolerated
|
|
149
|
+
# downstream by the existing `other_class == "NilClass"`
|
|
150
|
+
# check (the nullable-slot resets to nil between work).
|
|
151
|
+
canonical = writes.find { |w| ivar_class_for(w[:type]) != "NilClass" }
|
|
152
|
+
return [] if canonical.nil?
|
|
153
|
+
|
|
154
|
+
first_class = ivar_class_for(canonical[:type])
|
|
155
|
+
return [] if first_class.nil?
|
|
156
|
+
|
|
157
|
+
canonical_index = writes.index(canonical)
|
|
158
|
+
writes[(canonical_index + 1)..].filter_map do |write|
|
|
159
|
+
other_class = ivar_class_for(write[:type])
|
|
160
|
+
next nil if other_class.nil? || other_class == "NilClass" || other_class == first_class
|
|
161
|
+
next nil if declaration_admits?(write[:declared], canonical[:type], write[:type])
|
|
162
|
+
next nil if separate_invocations?(write, other_class, writes)
|
|
163
|
+
|
|
164
|
+
build_ivar_write_mismatch_diagnostic(path, write[:node], class_name, ivar_name, first_class, other_class)
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
# ADR-125 — a divergent write is never live together with the writes it conflicts with when the class
|
|
169
|
+
# serves one entry point per instance (a plugin-declared per-invocation class, e.g. a Rails controller:
|
|
170
|
+
# one action per request) and every conflicting write — non-nil, of a concrete class other than this
|
|
171
|
+
# write's — sits in a DIFFERENT action of the same class. An action is a public method no declared
|
|
172
|
+
# non-action macro names (`before_action :x`, `helper_method :y`); {IvarWriteCollector} decides it. A
|
|
173
|
+
# conflicting write in a private or protected helper, a callback target, a `helper_method`,
|
|
174
|
+
# `initialize`, or the same method keeps the finding. Which helper each action reaches is not proved
|
|
175
|
+
# here.
|
|
176
|
+
def self.separate_invocations?(write, write_class, writes)
|
|
177
|
+
return false unless write[:action]
|
|
178
|
+
|
|
179
|
+
writes.all? do |other|
|
|
180
|
+
other_class = ivar_class_for(other[:type])
|
|
181
|
+
next true if other_class.nil? || other_class == "NilClass" || other_class == write_class
|
|
182
|
+
|
|
183
|
+
other[:action] && other[:method_name] != write[:method_name]
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def self.declaration_admits?(declared, *write_types)
|
|
188
|
+
return false if declared.nil?
|
|
189
|
+
|
|
190
|
+
write_types.none? { |type| Inference::Acceptance.accepts(declared, type, mode: :gradual).no? }
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
# Pulls a single concrete class name from an ivar write's rvalue type. Returns nil when the type is
|
|
194
|
+
# too unstable to compare (Union / Dynamic / IntegerRange / etc.). `concrete_class_name` already
|
|
195
|
+
# covers Nominal / Singleton / Constant / Tuple / HashShape; the wrapper exists so the ivar rule can
|
|
196
|
+
# extend the envelope (or apply different filters) without disturbing the call rules.
|
|
197
|
+
#
|
|
198
|
+
# `TrueClass` / `FalseClass` are both normalised to `"bool"` here so the common boolean-flag idiom
|
|
199
|
+
# (`@loaded = false` in `initialize` then `@loaded = true` on first work) doesn't fire the mismatch
|
|
200
|
+
# rule. A real `bool → String` drift still trips because the second write's `ivar_class_for` returns
|
|
201
|
+
# `"String"`.
|
|
202
|
+
def self.ivar_class_for(type)
|
|
203
|
+
name = ReceiverPredicates.concrete_class_name(type)
|
|
204
|
+
return "bool" if %w[TrueClass FalseClass].include?(name)
|
|
205
|
+
|
|
206
|
+
name
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def self.build_ivar_write_mismatch_diagnostic(path, node, class_name, ivar_name, first_class, other_class)
|
|
210
|
+
Diagnostic.from_name_loc(
|
|
211
|
+
node,
|
|
212
|
+
rule: RULE_IVAR_WRITE_MISMATCH,
|
|
213
|
+
path: path,
|
|
214
|
+
message: "instance variable `#{ivar_name}' on #{class_name} was previously assigned " \
|
|
215
|
+
"#{first_class}; this write assigns #{other_class}",
|
|
216
|
+
severity: :error
|
|
217
|
+
)
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
private_class_method :ivar_mismatch_diagnostics_for, :separate_invocations?, :declaration_admits?,
|
|
221
|
+
:ivar_class_for, :build_ivar_write_mismatch_diagnostic
|
|
222
|
+
|
|
96
223
|
private
|
|
97
224
|
|
|
98
225
|
def walk(node, qualified_prefix)
|
|
@@ -201,7 +328,7 @@ module Rigor
|
|
|
201
328
|
# discovery table does not hold, or one a later `define_method` / alias / unplaceable write contests
|
|
202
329
|
# (#2013). `initialize` and the other lifecycle hooks are private whatever the table says.
|
|
203
330
|
def method_visibility(scope, class_name, method_name)
|
|
204
|
-
return :private if
|
|
331
|
+
return :private if OverrideVisibility::IMPLICITLY_PRIVATE_METHODS.include?(method_name)
|
|
205
332
|
return nil if scope.discovery.contested?(:discovered_method_visibilities, [class_name, method_name])
|
|
206
333
|
|
|
207
334
|
scope.discovered_method_visibility(class_name, method_name)
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "prism"
|
|
4
|
+
require_relative "../../reflection"
|
|
5
|
+
require_relative "../../type"
|
|
6
|
+
require_relative "../../inference/key_presence_guard"
|
|
7
|
+
require_relative "../diagnostic"
|
|
8
|
+
require_relative "declaration_sourced_guard"
|
|
9
|
+
require_relative "receiver_predicates"
|
|
10
|
+
require_relative "rule_ids"
|
|
11
|
+
|
|
12
|
+
module Rigor
|
|
13
|
+
module Analysis
|
|
14
|
+
module CheckRules
|
|
15
|
+
# ADR-116 WD1 — `call.possible-nil-receiver` (slice 7 phase 14): a call on a local variable whose type
|
|
16
|
+
# is a union carrying `nil`, to a method `NilClass` does not define, where every non-nil arm does.
|
|
17
|
+
#
|
|
18
|
+
# The entry point is {.diagnostic}, called by `CheckRules.call_node_diagnostics`.
|
|
19
|
+
# {.union_contains_nil?} and {.nil_class_has_method?} are public because `CheckRules`' argument-type
|
|
20
|
+
# rule asks the same two questions. It reads {ReceiverPredicates}, {DeclarationSourcedGuard} and
|
|
21
|
+
# `Inference::KeyPresenceGuard`, and calls nothing in `CheckRules`.
|
|
22
|
+
module NilReceiver
|
|
23
|
+
module_function
|
|
24
|
+
|
|
25
|
+
# Slice 7 phase 14 — nil-receiver diagnostic. Fires when
|
|
26
|
+
# the receiver type is a `Type::Union` containing a
|
|
27
|
+
# nil-bearing member (`Constant[nil]` or
|
|
28
|
+
# `Nominal[NilClass]`) AND the called method does not
|
|
29
|
+
# exist on `NilClass`. This is the canonical "you forgot
|
|
30
|
+
# to nil-check before calling X" signal: the engine has
|
|
31
|
+
# proved that on at least one execution path the receiver
|
|
32
|
+
# is nil, and the call would raise NoMethodError.
|
|
33
|
+
#
|
|
34
|
+
# The rule deliberately ignores receivers that are
|
|
35
|
+
# exactly `Constant[nil]` / `Nominal[NilClass]` (those
|
|
36
|
+
# are already covered by `undefined_method_diagnostic`)
|
|
37
|
+
# and union receivers where every member already
|
|
38
|
+
# disqualifies the call (avoid duplicating the
|
|
39
|
+
# undefined-method diagnostic).
|
|
40
|
+
def diagnostic(path, call_node, facts, lexical_sites = nil)
|
|
41
|
+
return nil if call_node.receiver.nil?
|
|
42
|
+
# Safe-navigation calls (`recv&.method`) already
|
|
43
|
+
# short-circuit on nil at runtime, so a nil-bearing
|
|
44
|
+
# receiver is not a bug for them.
|
|
45
|
+
return nil if call_node.safe_navigation?
|
|
46
|
+
# Restrict to direct local-variable reads. Local
|
|
47
|
+
# narrowing (Slice 6 phase 1) is the only narrowing
|
|
48
|
+
# surface that can prove a guard like
|
|
49
|
+
# `return if x.nil?` removed nil from the union, so
|
|
50
|
+
# firing on chained / method-call receivers would
|
|
51
|
+
# produce false positives we cannot suppress.
|
|
52
|
+
return nil unless call_node.receiver.is_a?(Prism::LocalVariableReadNode)
|
|
53
|
+
|
|
54
|
+
scope = facts.scope
|
|
55
|
+
return nil if scope.nil?
|
|
56
|
+
|
|
57
|
+
# ADR-58 WD1 — a receiver whose `nil` constituent is purely
|
|
58
|
+
# declaration-sourced (the class-ivar index seed of a ctor
|
|
59
|
+
# `@x = nil` written in another method, possibly copied into a
|
|
60
|
+
# local via `r = @right`) does not fire by default: the working
|
|
61
|
+
# program's cross-method invariant is assumed per the robustness
|
|
62
|
+
# principle. The nil stays in the displayed type; only its use as
|
|
63
|
+
# diagnostic fuel is withheld. Any flow-live touch (method-local
|
|
64
|
+
# nil write, failed-guard narrowing) drops the mark upstream, so
|
|
65
|
+
# flow-observed nil keeps firing exactly as before. The receiver
|
|
66
|
+
# is already narrowed to a local read above, so this asks
|
|
67
|
+
# {DeclarationSourcedGuard} exactly what it asked before — but it
|
|
68
|
+
# now asks it through the predicate the argument-type gates share
|
|
69
|
+
# (issue #324), which is what keeps the two rules from drifting.
|
|
70
|
+
#
|
|
71
|
+
# Issue #1362 — a local copied from a global still on its declared seed (`sep = $/`) is asked against the
|
|
72
|
+
# file's writes to that global instead: its declared `nil` is withheld, and one the file writes still fires.
|
|
73
|
+
return nil if DeclarationSourcedGuard.withholds_nil?(call_node.receiver, scope)
|
|
74
|
+
|
|
75
|
+
# ADR-67 WD6b — an inferred-parameter receiver's type (incl. any nil constituent unioned in from a
|
|
76
|
+
# nil call site) is an open-call-site lower bound; a possible-nil firing against it is an FP by
|
|
77
|
+
# construction. Decline.
|
|
78
|
+
return nil if scope.inferred_param?(call_node.receiver.name)
|
|
79
|
+
|
|
80
|
+
receiver_type = facts.receiver_type
|
|
81
|
+
return nil unless receiver_type.is_a?(Type::Union)
|
|
82
|
+
|
|
83
|
+
# The rule only fires when the analyzer has access to
|
|
84
|
+
# an RBS loader; without it, the per-member method-
|
|
85
|
+
# presence checks below cannot rule out a sound call.
|
|
86
|
+
return nil unless Rigor::Reflection.rbs_class_known?("NilClass", scope: scope)
|
|
87
|
+
|
|
88
|
+
return nil unless nil_bearing_union_witnesses?(receiver_type, call_node.name, scope)
|
|
89
|
+
return nil if nil_receiver_withheld?(call_node, receiver_type, scope, facts.scope_index, lexical_sites)
|
|
90
|
+
|
|
91
|
+
build_nil_receiver_diagnostic(path, call_node)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# The declines `call.possible-nil-receiver` asks only once a report would fire.
|
|
95
|
+
def nil_receiver_withheld?(call_node, receiver_type, scope, scope_index, lexical_sites)
|
|
96
|
+
# Issue #1703 — a `nil` that only a `key?` guard on the same receiver and key rules out. It re-walks the file
|
|
97
|
+
# once with guards on, and only to withhold this report.
|
|
98
|
+
return true if Inference::KeyPresenceGuard.withholds_nil?(call_node, receiver_type, lexical_sites&.root,
|
|
99
|
+
scope_index)
|
|
100
|
+
|
|
101
|
+
# ADR-121 WD7 — a refinement of `NilClass` (or one Rigor cannot read) in effect may define the name.
|
|
102
|
+
ReceiverPredicates.refined_method_in_effect?("NilClass", call_node, scope, :instance, lexical_sites)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# The receiver-type half of the rule, factored out of the node-shape
|
|
106
|
+
# guards above: the union must carry nil, must carry a non-nil arm the
|
|
107
|
+
# presence question can be asked of, must support the method on every
|
|
108
|
+
# non-nil arm (so the call is only wrong on the nil path), and the
|
|
109
|
+
# method must be absent from `NilClass` (so the nil path really raises).
|
|
110
|
+
def nil_bearing_union_witnesses?(receiver_type, method_name, scope)
|
|
111
|
+
union_contains_nil?(receiver_type) &&
|
|
112
|
+
union_has_nameable_non_nil_arm?(receiver_type, scope) &&
|
|
113
|
+
union_method_present_on_non_nil?(receiver_type, method_name, scope) &&
|
|
114
|
+
!nil_class_has_method?(method_name, scope)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def union_contains_nil?(union)
|
|
118
|
+
union.members.any? { |member| ReceiverPredicates.nil_member?(member) }
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# Possible-nil may witness only where the presence question below is
|
|
122
|
+
# ANSWERABLE. `method_present_anywhere?` reports "present" for a
|
|
123
|
+
# nameless arm (Dynamic / Top / Bot) — the permissive polarity the
|
|
124
|
+
# union-undefined-method rule's FP safety rests on — so a union whose
|
|
125
|
+
# non-nil arms are ALL nameless satisfied that gate vacuously and fired
|
|
126
|
+
# on every method name, including names defined on no class anywhere.
|
|
127
|
+
# That inverted the intent: the gate suppressed exactly where knowledge
|
|
128
|
+
# exists (`String | nil` calling a nonexistent method stays silent) and
|
|
129
|
+
# permitted exactly where none does. Requiring one nameable concrete
|
|
130
|
+
# arm restores the polarity without touching the shared helper:
|
|
131
|
+
# `String | nil` keeps firing, and so does `Dynamic | String | nil` —
|
|
132
|
+
# the nameless arm stays permissive inside the all-arms check, which is
|
|
133
|
+
# only about the arms' method surface. That union no longer arises from
|
|
134
|
+
# a merge re-joining the narrowed edges of one untyped local, which
|
|
135
|
+
# binds it back to `Dynamic[top]` (issue #1840,
|
|
136
|
+
# `Inference::UntypedRejoin`); it still does when the program writes
|
|
137
|
+
# the `nil` (`x = nil if c`) and no `nil?` edge strips it before the
|
|
138
|
+
# re-joining merge, or when the arms are not a narrowing of one
|
|
139
|
+
# untyped value.
|
|
140
|
+
def union_has_nameable_non_nil_arm?(union, scope)
|
|
141
|
+
union.members.any? do |m|
|
|
142
|
+
next false if ReceiverPredicates.nil_member?(m)
|
|
143
|
+
|
|
144
|
+
class_name = ReceiverPredicates.concrete_class_name(m)
|
|
145
|
+
next false if class_name.nil?
|
|
146
|
+
|
|
147
|
+
# Issue #574 — nameable is not the same as ANSWERABLE. `method_present_anywhere?` reports
|
|
148
|
+
# "present" for a named arm nothing knows the surface of, purely because nothing is known —
|
|
149
|
+
# which is the same vacuity this gate's docstring says it exists to prevent, one level in. A
|
|
150
|
+
# plugin-minted nominal like `ActionController::Parameters` ships no RBS and has no project
|
|
151
|
+
# source, so it counted as a full witness and `q = params[:q]; q.strip` fired at ERROR severity
|
|
152
|
+
# on correct Rails code.
|
|
153
|
+
Rigor::Reflection.rbs_class_known?(class_name, scope: scope) ||
|
|
154
|
+
scope.discovered_classes.key?(class_name)
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# The non-nil members must collectively support the
|
|
159
|
+
# method (i.e. for every non-nil member, the method
|
|
160
|
+
# exists on its class via RBS or in-source discovery).
|
|
161
|
+
# Without this guard, the rule would also fire on calls
|
|
162
|
+
# that are unsound on the non-nil branch — that is the
|
|
163
|
+
# `undefined_method_diagnostic` rule's job, and we want
|
|
164
|
+
# exactly one diagnostic per offending call site.
|
|
165
|
+
def union_method_present_on_non_nil?(union, method_name, scope)
|
|
166
|
+
non_nil_members = union.members.reject { |m| ReceiverPredicates.nil_member?(m) }
|
|
167
|
+
return false if non_nil_members.empty?
|
|
168
|
+
|
|
169
|
+
non_nil_members.all? { |m| ReceiverPredicates.method_present_anywhere?(m, method_name, scope) }
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def nil_class_has_method?(method_name, scope)
|
|
173
|
+
definition = Rigor::Reflection.instance_definition("NilClass", scope: scope)
|
|
174
|
+
return false if definition.nil?
|
|
175
|
+
|
|
176
|
+
!definition.methods[method_name.to_sym].nil?
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def build_nil_receiver_diagnostic(path, call_node)
|
|
180
|
+
Diagnostic.from_message_loc(
|
|
181
|
+
call_node,
|
|
182
|
+
rule: RULE_NIL_RECEIVER,
|
|
183
|
+
path: path,
|
|
184
|
+
message: "possible nil receiver: `#{call_node.name}' is undefined on NilClass",
|
|
185
|
+
severity: :error,
|
|
186
|
+
method_name: call_node.name.to_s
|
|
187
|
+
)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
private_class_method :nil_receiver_withheld?, :nil_bearing_union_witnesses?, :union_has_nameable_non_nil_arm?,
|
|
191
|
+
:union_method_present_on_non_nil?, :build_nil_receiver_diagnostic
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
end
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../inference/rbs_type_translator"
|
|
4
|
+
require_relative "../diagnostic"
|
|
5
|
+
require_relative "override_support"
|
|
6
|
+
require_relative "rule_ids"
|
|
7
|
+
|
|
8
|
+
module Rigor
|
|
9
|
+
module Analysis
|
|
10
|
+
module CheckRules
|
|
11
|
+
# ADR-116 WD1 — `def.override-param-narrowed` (ADR-35 slice 3): an override whose positional parameter
|
|
12
|
+
# is narrower than the one it inherits.
|
|
13
|
+
#
|
|
14
|
+
# The one entry point is {.diagnostic}, called by `CheckRules.main_pass_node_diagnostics`. It reads
|
|
15
|
+
# {OverrideSupport} and calls nothing else in `CheckRules`.
|
|
16
|
+
module OverrideParamNarrowed
|
|
17
|
+
module_function
|
|
18
|
+
|
|
19
|
+
# ADR-35 slice 3 — `def.override-param-narrowed`. The Liskov signature rule for parameters
|
|
20
|
+
# (contravariance): an override may *widen* a parameter (accept a supertype — accepting more is
|
|
21
|
+
# safe) but MUST NOT *narrow* it. A caller holding the supertype passes a parent-typed argument; a
|
|
22
|
+
# narrowed override parameter cannot accept it.
|
|
23
|
+
#
|
|
24
|
+
# Direction (ADR-35 WD3, corrected): fire on `override_param.accepts(parent_param) == :no` — the
|
|
25
|
+
# override's (narrowed) slot cannot accept the wider parent argument type. WD4: type comparison at
|
|
26
|
+
# matching POSITIONAL parameter indices only; arity / keyword-requiredness divergence is out of
|
|
27
|
+
# scope for v1. Same WD1 both-sides-authored gate as slice 2; `untyped` / unbound-generic /
|
|
28
|
+
# interface parent params degrade to `Dynamic[Top]` and are skipped (FP-safe). To avoid
|
|
29
|
+
# overload-arm ambiguity, both sides must have exactly one method type.
|
|
30
|
+
def diagnostic(path, def_node, scope_index)
|
|
31
|
+
resolved = OverrideSupport.resolve_authored_override(def_node, scope_index)
|
|
32
|
+
return nil if resolved.nil?
|
|
33
|
+
|
|
34
|
+
scope, override_method, parent_class, parent_method = resolved
|
|
35
|
+
parent_type_vars = OverrideSupport.ancestor_instantiation_type_vars(scope, parent_class)
|
|
36
|
+
override_params = positional_param_types(override_method, environment: scope.environment)
|
|
37
|
+
parent_params = positional_param_types(parent_method, type_vars: parent_type_vars,
|
|
38
|
+
environment: scope.environment)
|
|
39
|
+
return nil if override_params.nil? || parent_params.nil?
|
|
40
|
+
|
|
41
|
+
index = first_narrowed_param_index(override_params, parent_params)
|
|
42
|
+
return nil if index.nil?
|
|
43
|
+
|
|
44
|
+
build_override_param_narrowed_diagnostic(
|
|
45
|
+
path, def_node, parent_class, index, parent_params[index], override_params[index]
|
|
46
|
+
)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Translated positional (required + optional) parameter types of a method's single method type, or
|
|
50
|
+
# nil when the method is overloaded (multiple method types — arm mapping is ambiguous) or the
|
|
51
|
+
# parameter list is not introspectable. Per-position translation failures yield `nil` at that slot
|
|
52
|
+
# (skipped by the comparison). `self`/`instance` translate with `self_type: nil` (→
|
|
53
|
+
# `Dynamic[Top]`), matching the return-side handling.
|
|
54
|
+
# `type_vars:` — ADR-35 WD9 tier 1, parent side only. Substitutes the generic-instantiation
|
|
55
|
+
# map (parent class's type params → the subclass's instantiation) so a parent `(T)` parameter
|
|
56
|
+
# is compared at its instantiated type. Empty (the default, and the override side) keeps the
|
|
57
|
+
# pre-WD9 degrade-to-`Dynamic[Top]` behaviour.
|
|
58
|
+
def positional_param_types(method_def, type_vars: {}, environment: nil)
|
|
59
|
+
method_types = method_def.method_types
|
|
60
|
+
return nil unless method_types.size == 1
|
|
61
|
+
|
|
62
|
+
func = method_types.first.type
|
|
63
|
+
return nil unless func.respond_to?(:required_positionals)
|
|
64
|
+
|
|
65
|
+
(func.required_positionals + func.optional_positionals).map do |param|
|
|
66
|
+
Inference::RbsTypeTranslator.translate(
|
|
67
|
+
param.type, self_type: nil, instance_type: nil, type_vars: type_vars,
|
|
68
|
+
alias_expander: environment&.rbs_loader
|
|
69
|
+
)
|
|
70
|
+
rescue StandardError
|
|
71
|
+
nil
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Index of the first positional parameter the override narrows relative to the parent, or nil. A
|
|
76
|
+
# position is a violation when the override's slot cannot accept the parent's argument type
|
|
77
|
+
# (`override_param.accepts(parent_param) == :no`). Positions where either side is
|
|
78
|
+
# missing/untranslatable, or the parent type degraded to `Dynamic[Top]` (untyped / unbound generic
|
|
79
|
+
# / interface), are skipped.
|
|
80
|
+
def first_narrowed_param_index(override_params, parent_params)
|
|
81
|
+
count = [override_params.size, parent_params.size].min
|
|
82
|
+
count.times do |i|
|
|
83
|
+
override_param = override_params[i]
|
|
84
|
+
parent_param = parent_params[i]
|
|
85
|
+
next if override_param.nil? || parent_param.nil?
|
|
86
|
+
next if OverrideSupport.dynamic_top?(parent_param) || OverrideSupport.dynamic_top?(override_param)
|
|
87
|
+
|
|
88
|
+
return i if override_param.accepts(parent_param).no?
|
|
89
|
+
end
|
|
90
|
+
nil
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def build_override_param_narrowed_diagnostic(path, def_node, parent_class, index, parent_param, override_param)
|
|
94
|
+
Diagnostic.from_name_loc(
|
|
95
|
+
def_node,
|
|
96
|
+
rule: RULE_OVERRIDE_PARAM_NARROWED,
|
|
97
|
+
path: path,
|
|
98
|
+
message: "parameter #{index + 1} of `#{def_node.name}' narrowed from " \
|
|
99
|
+
"#{parent_param.describe(:short)} to #{override_param.describe(:short)} " \
|
|
100
|
+
"(overrides #{parent_class}##{def_node.name}); breaks substitutability",
|
|
101
|
+
severity: :warning,
|
|
102
|
+
method_name: def_node.name.to_s
|
|
103
|
+
)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
private_class_method :positional_param_types, :first_narrowed_param_index,
|
|
107
|
+
:build_override_param_narrowed_diagnostic
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|