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
|
@@ -9,24 +9,6 @@ require_relative "rbs_type_translator"
|
|
|
9
9
|
|
|
10
10
|
module Rigor
|
|
11
11
|
module Inference
|
|
12
|
-
# Builds the entry scope of a method body by translating the method's parameter list into a
|
|
13
|
-
# `name -> Rigor::Type` map.
|
|
14
|
-
#
|
|
15
|
-
# Parameter types come from the surrounding class's RBS signature when one is available;
|
|
16
|
-
# otherwise every parameter defaults to `Dynamic[Top]`. The default is the Slice 1 fail-soft
|
|
17
|
-
# answer for unknown values, so a method whose RBS signature is missing or whose parameters
|
|
18
|
-
# cannot be matched still binds every name into the scope (a method body whose `Local x`
|
|
19
|
-
# reads return `Dynamic[Top]` instead of falling through to the unbound-local
|
|
20
|
-
# `Dynamic[Top]` event is the same observable type, but the binding presence is what later
|
|
21
|
-
# slices need to attach narrowing facts to).
|
|
22
|
-
#
|
|
23
|
-
# The class context (`class_path:`) and `singleton:` flag are supplied by the caller (the
|
|
24
|
-
# StatementEvaluator) which threads them as the lexical class scope. The binder makes no
|
|
25
|
-
# assumption about how that context was computed; it only uses it to build the
|
|
26
|
-
# `(class_name, method_name)` lookup key for `Rigor::Environment::RbsLoader#instance_method`
|
|
27
|
-
# / `#singleton_method`.
|
|
28
|
-
#
|
|
29
|
-
# See docs/internal-spec/inference-engine.md for the binding contract.
|
|
30
12
|
# Leaf-name extraction for a destructured positional parameter (`Prism::MultiTargetNode`).
|
|
31
13
|
# Stateless; lifted out of {MethodParameterBinder} so the binder's class length stays in
|
|
32
14
|
# budget.
|
|
@@ -162,6 +144,24 @@ module Rigor
|
|
|
162
144
|
end
|
|
163
145
|
end
|
|
164
146
|
|
|
147
|
+
# Builds the entry scope of a method body by translating the method's parameter list into a
|
|
148
|
+
# `name -> Rigor::Type` map.
|
|
149
|
+
#
|
|
150
|
+
# Parameter types come from the surrounding class's RBS signature when one is available;
|
|
151
|
+
# otherwise every parameter defaults to `Dynamic[Top]`. The default is the Slice 1 fail-soft
|
|
152
|
+
# answer for unknown values, so a method whose RBS signature is missing or whose parameters
|
|
153
|
+
# cannot be matched still binds every name into the scope (a method body whose `Local x`
|
|
154
|
+
# reads return `Dynamic[Top]` instead of falling through to the unbound-local
|
|
155
|
+
# `Dynamic[Top]` event is the same observable type, but the binding presence is what later
|
|
156
|
+
# slices need to attach narrowing facts to).
|
|
157
|
+
#
|
|
158
|
+
# The class context (`class_path:`) and `singleton:` flag are supplied by the caller (the
|
|
159
|
+
# StatementEvaluator) which threads them as the lexical class scope. The binder makes no
|
|
160
|
+
# assumption about how that context was computed; it only uses it to build the
|
|
161
|
+
# `(class_name, method_name)` lookup key for `Rigor::Environment::RbsLoader#instance_method`
|
|
162
|
+
# / `#singleton_method`.
|
|
163
|
+
#
|
|
164
|
+
# See docs/internal-spec/inference-engine.md for the binding contract.
|
|
165
165
|
class MethodParameterBinder
|
|
166
166
|
# @param class_path — the qualified name of the class the method is defined in
|
|
167
167
|
# (e.g., `"Foo::Bar"`), or `nil` for a top-level `def` outside any class. When `nil` (or
|
|
@@ -44,8 +44,9 @@ module Rigor
|
|
|
44
44
|
# call covers the instance methods written before it as well as after it, while a named call takes only a
|
|
45
45
|
# def written before it. A change to what `module_function` means must decide whether that reader follows.
|
|
46
46
|
#
|
|
47
|
-
# The deferred-ranges prescan asks `
|
|
48
|
-
# `rigor/inference/scope_indexer
|
|
47
|
+
# The deferred-ranges prescan asks `DeclarationWalk::Rules.receiver_eval_call?` and `ScopeIndexer.def_side`,
|
|
48
|
+
# so `rigor/inference/scope_indexer`, which loads the rules, must be loaded before it runs. This file does not
|
|
49
|
+
# require it:
|
|
49
50
|
# `scope_indexer.rb` requires this file, and a require back would be circular. The other entry points need
|
|
50
51
|
# only Prism.
|
|
51
52
|
#
|
|
@@ -228,7 +229,7 @@ module Rigor
|
|
|
228
229
|
# body where the walk opens one.
|
|
229
230
|
#
|
|
230
231
|
# `qualified_prefix` names the owner, and `in_singleton_class` says whether the body is a
|
|
231
|
-
# `class <<` body; both feed `ScopeIndexer.
|
|
232
|
+
# `class <<` body; both feed `ScopeIndexer.def_side`.
|
|
232
233
|
def prescan_deferred(node, qualified_prefix, in_singleton_class, offsets, ranges, nested: false)
|
|
233
234
|
return unless node.is_a?(Prism::Node)
|
|
234
235
|
return if node.is_a?(Prism::ClassNode) || node.is_a?(Prism::ModuleNode) ||
|
|
@@ -356,7 +357,7 @@ module Rigor
|
|
|
356
357
|
Spellings.prescan(node, arguments, qualified_prefix, in_singleton_class, offsets, ranges)
|
|
357
358
|
elsif visibility_reset?(node)
|
|
358
359
|
offsets << [node.location.start_offset, nested ? :maybe_off : :off]
|
|
359
|
-
elsif
|
|
360
|
+
elsif DeclarationWalk::Rules.receiver_eval_call?(node) || (node.block && DeclarationWalk::Rules.meta_new_constant_rvalue?(node))
|
|
360
361
|
prescan_eval_call(node, qualified_prefix, in_singleton_class, offsets, ranges)
|
|
361
362
|
else
|
|
362
363
|
return false
|
|
@@ -126,6 +126,8 @@ module Rigor
|
|
|
126
126
|
# not invalidate the receiver's facts.
|
|
127
127
|
def pure_self_returner?(method_name) = PURE_SELF_RETURNERS.include?(method_name)
|
|
128
128
|
|
|
129
|
+
NO_ARG_TYPES = [].freeze
|
|
130
|
+
|
|
129
131
|
# Returns a scope with the call's receiver widened, for every variable the receiver expression
|
|
130
132
|
# can evaluate to ({ReceiverAlias.candidates}) whose current binding is a literal-shape carrier
|
|
131
133
|
# (`Tuple` / `HashShape`) or an empty-witness refinement (`non-empty-array` /
|
|
@@ -136,8 +138,6 @@ module Rigor
|
|
|
136
138
|
# scope the arguments are evaluated in. They are what the widened carrier JOINS its added
|
|
137
139
|
# content evidence from (issue #560); an empty list means "no evidence", which reproduces the
|
|
138
140
|
# pre-join behaviour exactly.
|
|
139
|
-
NO_ARG_TYPES = [].freeze
|
|
140
|
-
|
|
141
141
|
# `rewritten_element` is the element a typed element rewriter stores ({RewriteMutation.typed}), or `nil`.
|
|
142
142
|
def widen_after_call(call_node:, current_scope:, arg_types: NO_ARG_TYPES, rewritten_element: nil)
|
|
143
143
|
return current_scope if pure_self_returner?(call_node.name)
|
|
@@ -272,7 +272,7 @@ module Rigor
|
|
|
272
272
|
# g(y)`, `arr.push(x) if cond`) are all caught.
|
|
273
273
|
def widen_after_block(call_node:, outer_scope:)
|
|
274
274
|
block = call_node.block
|
|
275
|
-
return
|
|
275
|
+
return widen_after_symbol_proc(call_node, outer_scope) if DeepErasure.symbol_proc_mutation?(block)
|
|
276
276
|
return outer_scope unless block.is_a?(Prism::BlockNode)
|
|
277
277
|
|
|
278
278
|
body = block.body
|
|
@@ -283,6 +283,18 @@ module Rigor
|
|
|
283
283
|
DeepErasure.widen_element_aliases(call_node.receiver, block.body, names, scope)
|
|
284
284
|
end
|
|
285
285
|
|
|
286
|
+
# `a.each(&:strip!)` mutates every element `a` hands the block ({DeepErasure.widen_symbol_proc}). Issue #3340 —
|
|
287
|
+
# and where the receiver is a literal Array (`[xs, ys].each(&:clear)`), each element that is a variable read is
|
|
288
|
+
# itself the object the mutator runs on, so it widens as the direct call `xs.clear` widens it.
|
|
289
|
+
def widen_after_symbol_proc(call_node, outer_scope)
|
|
290
|
+
scope = DeepErasure.widen_symbol_proc(call_node, outer_scope)
|
|
291
|
+
receiver = call_node.receiver
|
|
292
|
+
return scope unless receiver.is_a?(Prism::ArrayNode)
|
|
293
|
+
|
|
294
|
+
method_name = call_node.block.expression.unescaped.to_sym
|
|
295
|
+
receiver.elements.reduce(scope) { |acc, element| widen_receiver_aliases(element, method_name, acc) }
|
|
296
|
+
end
|
|
297
|
+
|
|
286
298
|
def walk_for_outer_mutations(node, scope)
|
|
287
299
|
return scope if node.nil?
|
|
288
300
|
|
|
@@ -535,14 +547,15 @@ module Rigor
|
|
|
535
547
|
# Straight-line evidence is ALWAYS incomplete, so a straight-line join may never close the
|
|
536
548
|
# parameter it contributes to.
|
|
537
549
|
#
|
|
538
|
-
# This seam sees ONE store — the call being evaluated. The widening it feeds
|
|
539
|
-
#
|
|
540
|
-
#
|
|
550
|
+
# This seam sees ONE store — the call being evaluated. The widening it feeds replaces the
|
|
551
|
+
# literal carrier with a `Nominal`, and {MutationRejoin.widen_nominal} re-grows a `Nominal`
|
|
552
|
+
# only while a parameter still carries a gradual arm, so a join that closed the parameter
|
|
553
|
+
# would leave the NEXT store invisible. Closing over one sample of a growing
|
|
541
554
|
# population is therefore a wrong type, not an imprecise one:
|
|
542
555
|
#
|
|
543
556
|
# a = []
|
|
544
557
|
# a.push(1) # joins -> Array[Integer]
|
|
545
|
-
# a.push("s") # DECLINED -- pre-state is a Nominal now
|
|
558
|
+
# a.push("s") # DECLINED -- pre-state is a closed Nominal now
|
|
546
559
|
# a.last.upcase # correct Ruby, prints "S"
|
|
547
560
|
#
|
|
548
561
|
# closed to `Array[Integer]` and drew `undefined method 'upcase' for Integer` on code that
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../type"
|
|
4
|
+
|
|
5
|
+
module Rigor
|
|
6
|
+
module Inference
|
|
7
|
+
module Narrowing
|
|
8
|
+
# Issue #3445 — the falsey edges of the `when` literal conditions that can exhaust a `case` subject, so the
|
|
9
|
+
# absent `else` of an exhaustive `case`/`when` drops its `nil` arm ({Narrowing.exhausted_when_case?}). The
|
|
10
|
+
# truthy edges and the condition dispatch stay in `Narrowing.case_when_types`.
|
|
11
|
+
module CaseLiterals
|
|
12
|
+
module_function
|
|
13
|
+
|
|
14
|
+
# The falsey edge of `(low..high) === n` on an Integer-rooted `type`: each member keeps the part outside
|
|
15
|
+
# `[low, high]`, which is what a failed `Range#===` on an Integer proves. A member the range covers collapses
|
|
16
|
+
# to `Bot`, one it overlaps at an end is trimmed (`Integer[1..6]` minus `1..3` is `Integer[4..6]`), and one
|
|
17
|
+
# it splits keeps both pieces (`Integer[1..6]` minus `3..4` is `Integer[1..2] | Integer[5..6]`). An open end
|
|
18
|
+
# is a symbolic infinity and leaves no piece on its side.
|
|
19
|
+
def integer_outside_range(type, low, high)
|
|
20
|
+
if type.is_a?(Type::Union)
|
|
21
|
+
return Type::Combinator.union(*type.members.map { |m| integer_outside_range(m, low, high) })
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
below = low.is_a?(Integer) ? Narrowing.narrow_integer_comparison(type, :<, low) : Type::Combinator.bot
|
|
25
|
+
above = high.is_a?(Integer) ? Narrowing.narrow_integer_comparison(type, :>, high) : Type::Combinator.bot
|
|
26
|
+
Type::Combinator.union(below, above)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# A class-guard result for a `when` condition. A Range that missed the Integer rule reads as a guard on its
|
|
30
|
+
# endpoints' class (`Numeric`, `String`), which holds on its truthy edge, but a failed `(a..b) === v` proves
|
|
31
|
+
# only that `v` is outside `[a, b]`, not that it is no `String`: its falsey edge keeps `falsey_acc` and the
|
|
32
|
+
# `case` its unmatched path (`case s when "a".."m" then 1 end` on `s: String` is `1 | nil`). `condition` is
|
|
33
|
+
# unwrapped of its parentheses.
|
|
34
|
+
def class_fallback(condition, result, falsey_acc)
|
|
35
|
+
return result unless condition.is_a?(Prism::RangeNode)
|
|
36
|
+
|
|
37
|
+
result.merge(falsey: falsey_acc, fully_narrowable: false)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# `:a === x` is `Symbol#==`, so on a subject that is a finite union of trusted literals (`:a | :b`) a plain
|
|
41
|
+
# Symbol literal condition keeps the members equal to `:a` on the truthy edge and removes them on the falsey
|
|
42
|
+
# edge. nil for any other condition, and for a broader subject (`Symbol`, `Dynamic`), which has no known
|
|
43
|
+
# domain to remove a literal from. `condition` is unwrapped of its parentheses.
|
|
44
|
+
def symbol_when_result(current, condition, falsey_acc)
|
|
45
|
+
return nil unless condition.is_a?(Prism::SymbolNode) && condition.value_loc
|
|
46
|
+
return nil unless Complements.finite_trusted_literal_domain?(current)
|
|
47
|
+
|
|
48
|
+
symbol = Type::Combinator.constant_of(condition.unescaped.to_sym)
|
|
49
|
+
{
|
|
50
|
+
truthy: Complements.narrow_finite_equal(current, symbol),
|
|
51
|
+
falsey: Complements.narrow_finite_not_equal(falsey_acc, symbol),
|
|
52
|
+
fully_narrowable: true
|
|
53
|
+
}
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../type"
|
|
4
|
+
|
|
5
|
+
module Rigor
|
|
6
|
+
module Inference
|
|
7
|
+
module Narrowing
|
|
8
|
+
# ADR-116 C1 — `narrow_class_dispatch`: the per-carrier narrowing for `Narrowing.narrow_class` and
|
|
9
|
+
# `Narrowing.narrow_not_class`. {.narrow_class_dispatch} takes the type, the class name and a
|
|
10
|
+
# `Narrowing::ClassNarrowingContext` (read through its `exact`, `polarity`, `environment` and `scope`
|
|
11
|
+
# accessors only, so this file does not name the carrier) and answers the narrowed type.
|
|
12
|
+
#
|
|
13
|
+
# Plain functions on `Rigor::Type` values. Calls nothing in `Narrowing`; the two public narrowing entries
|
|
14
|
+
# are its only callers.
|
|
15
|
+
module ClassDispatch
|
|
16
|
+
module_function
|
|
17
|
+
|
|
18
|
+
# ----- narrow_class / narrow_not_class helpers -----
|
|
19
|
+
|
|
20
|
+
# Polarity-aware dispatch table for {.narrow_class} / {.narrow_not_class}. Avoids
|
|
21
|
+
# duplicating the per-carrier case statement and keeps each public surface a thin
|
|
22
|
+
# delegate; the per-carrier helpers know which polarity to apply by looking at
|
|
23
|
+
# `polarity:`.
|
|
24
|
+
def narrow_class_dispatch(type, class_name, context)
|
|
25
|
+
case type
|
|
26
|
+
when Type::Constant then narrow_constant_class(type, class_name, context)
|
|
27
|
+
when Type::Nominal then narrow_nominal_class(type, class_name, context)
|
|
28
|
+
when Type::Union then narrow_union_class(type, class_name, context)
|
|
29
|
+
when Type::Tuple then narrow_shape_class(type, "Array", class_name, context)
|
|
30
|
+
when Type::HashShape then narrow_shape_class(type, "Hash", class_name, context)
|
|
31
|
+
when Type::Singleton then narrow_singleton_class(type, class_name, context)
|
|
32
|
+
else narrow_other_class(type, class_name, context)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def narrow_constant_class(constant, class_name, context)
|
|
37
|
+
if context.polarity == :positive
|
|
38
|
+
narrow_constant_to_class(constant, class_name, context)
|
|
39
|
+
else
|
|
40
|
+
narrow_constant_not_class(constant, class_name, context)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def narrow_nominal_class(nominal, class_name, context)
|
|
45
|
+
if context.polarity == :positive
|
|
46
|
+
narrow_nominal_to_class(nominal, class_name, context)
|
|
47
|
+
else
|
|
48
|
+
narrow_nominal_not_class(nominal, class_name, context)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def narrow_union_class(union, class_name, context)
|
|
53
|
+
Type::Combinator.union(
|
|
54
|
+
*union.members.map { |member| narrow_class_dispatch(member, class_name, context) }
|
|
55
|
+
)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def narrow_shape_class(shape, projected_class, class_name, context)
|
|
59
|
+
if context.polarity == :positive
|
|
60
|
+
narrow_shape_to_class(shape, projected_class, class_name, context)
|
|
61
|
+
else
|
|
62
|
+
narrow_shape_not_class(shape, projected_class, class_name, context)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def narrow_singleton_class(singleton, class_name, context)
|
|
67
|
+
if context.polarity == :positive
|
|
68
|
+
narrow_singleton_to_class(singleton, class_name, context)
|
|
69
|
+
else
|
|
70
|
+
narrow_singleton_not_class(singleton, class_name, context)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def narrow_other_class(type, class_name, context)
|
|
75
|
+
context.polarity == :positive ? narrow_class_other(type, class_name) : type
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Issue #657 — `Bot` is the assertion "this can never match", and only a KNOWN-disjoint ordering
|
|
79
|
+
# supports it (the reason {#declines_bot?} exists, and the repro it was written against):
|
|
80
|
+
#
|
|
81
|
+
# module Taggable; def tag = "t"; end
|
|
82
|
+
# class Integer; include Taggable; end
|
|
83
|
+
# x = 1
|
|
84
|
+
# case x
|
|
85
|
+
# when Taggable then x.tag # reported unreachable; `1.is_a?(Taggable)` is true
|
|
86
|
+
# end
|
|
87
|
+
#
|
|
88
|
+
# The ordering is `:unknown` because an in-source `include` into a CORE class never reaches the
|
|
89
|
+
# environment's class ordering — the include is discovered in project source, `Integer`'s ancestry
|
|
90
|
+
# comes from RBS, and the two are not joined (the precision half, left in #657).
|
|
91
|
+
#
|
|
92
|
+
# `:unknown` joins to Dynamic, the same answer {#narrow_nominal_to_class} gives and for the same
|
|
93
|
+
# reason: keeping the old bound licenses `call.undefined-method` on the guard-proven branch. Keeping
|
|
94
|
+
# the literal was tried first and did exactly that — `s = "str"` under `when Unrelated` stayed
|
|
95
|
+
# `Constant["str"]` and reported `undefined method 'other'`, trading one false positive for
|
|
96
|
+
# another. The value is lost only on the guarded arm, which is where the guard just told us the
|
|
97
|
+
# environment's picture was incomplete.
|
|
98
|
+
def narrow_constant_to_class(constant, class_name, context)
|
|
99
|
+
rigor_class = constant.value.class.name
|
|
100
|
+
return constant if subclass_of?(rigor_class, class_name, context)
|
|
101
|
+
return Type::Combinator.untyped if declines_bot?(rigor_class, class_name, context)
|
|
102
|
+
|
|
103
|
+
Type::Combinator.bot
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def narrow_constant_not_class(constant, class_name, context)
|
|
107
|
+
rigor_class = constant.value.class.name
|
|
108
|
+
subclass_of?(rigor_class, class_name, context) ? Type::Combinator.bot : constant
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Narrow a Nominal under `is_a?(class_name)`: when the nominal's class is already a
|
|
112
|
+
# subclass of `class_name` (or matches under `exact: true`) preserve it; when
|
|
113
|
+
# `class_name` is a subclass of the nominal's class (`Nominal[Numeric]` under
|
|
114
|
+
# `is_a?(Integer)`) narrow DOWN to `Nominal[class_name]`; otherwise (disjoint
|
|
115
|
+
# hierarchies under `is_a?`, mismatch under `instance_of?`) collapse to `Bot`.
|
|
116
|
+
# Conservative when the analyzer environment cannot resolve either class.
|
|
117
|
+
#
|
|
118
|
+
# A disjoint `Bot` narrows the edge but is not always a verdict that the code is dead: see
|
|
119
|
+
# {.disjoint_nominal_guard?} (issue #1429).
|
|
120
|
+
def narrow_nominal_to_class(nominal, class_name, context)
|
|
121
|
+
return nominal if nominal.class_name == class_name
|
|
122
|
+
return exact_nominal_to_class(nominal, class_name, context) if context.exact
|
|
123
|
+
|
|
124
|
+
case class_ordering(nominal.class_name, class_name, context)
|
|
125
|
+
when :superclass then Type::Combinator.nominal_of(class_name)
|
|
126
|
+
when :disjoint then Type::Combinator.bot
|
|
127
|
+
when :subclass then nominal
|
|
128
|
+
else
|
|
129
|
+
# :unknown — the guard proved membership in a class the environment cannot order against the
|
|
130
|
+
# bound (an RBS-less gem class, typically). Keeping the old bound licenses `undefined-method`
|
|
131
|
+
# on the guard-proven branch (concurrent-ruby's `done.is_a?(Concurrent::Maybe)` kept `Array`
|
|
132
|
+
# and fired on `.value`); the honest join is Dynamic — the guard destroyed the old knowledge.
|
|
133
|
+
Type::Combinator.untyped
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# `instance_of?(class_name)` compares the exact class, so its truthy edge holds `class_name` itself. Issue
|
|
138
|
+
# #1429: when `class_name` is a class below the nominal's (`Numeric` under `instance_of?(Integer)`), that is
|
|
139
|
+
# the edge's type; the edge was `Bot` before, for every class but the nominal's own. A module is never an
|
|
140
|
+
# object's class, and any other ordering leaves no class the object can have, so those stay `Bot`.
|
|
141
|
+
def exact_nominal_to_class(nominal, class_name, context)
|
|
142
|
+
return Type::Combinator.bot if context.environment.rbs_module?(class_name)
|
|
143
|
+
return Type::Combinator.bot unless class_ordering(nominal.class_name, class_name, context) == :superclass
|
|
144
|
+
|
|
145
|
+
Type::Combinator.nominal_of(class_name)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def narrow_nominal_not_class(nominal, class_name, context)
|
|
149
|
+
return Type::Combinator.bot if nominal.class_name == class_name
|
|
150
|
+
return nominal if context.exact
|
|
151
|
+
|
|
152
|
+
ordering = class_ordering(nominal.class_name, class_name, context)
|
|
153
|
+
case ordering
|
|
154
|
+
when :subclass then Type::Combinator.bot
|
|
155
|
+
else nominal
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# A shape projects to `Array` / `Hash`, and reopening either of those to include a project module
|
|
160
|
+
# leaves the ordering `:unknown` for the same reason #657's `Integer` does — so `[1, 2]` under `when
|
|
161
|
+
# Taggable` reached the same unsupported `Bot`. The carrier differs; the missing evidence does not.
|
|
162
|
+
def narrow_shape_to_class(shape, projected_class, class_name, context)
|
|
163
|
+
return shape if subclass_of?(projected_class, class_name, context)
|
|
164
|
+
return Type::Combinator.untyped if declines_bot?(projected_class, class_name, context)
|
|
165
|
+
|
|
166
|
+
Type::Combinator.bot
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def narrow_shape_not_class(shape, projected_class, class_name, context)
|
|
170
|
+
subclass_of?(projected_class, class_name, context) ? Type::Combinator.bot : shape
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
# `Singleton[Foo]` is the *class object* `Foo`, an instance of `Class` (which is a
|
|
174
|
+
# subclass of `Module`). Asking `Foo.is_a?(Class)` returns true; `Foo.is_a?(Foo)`
|
|
175
|
+
# returns false unless `Foo` is `Class` itself. We approximate this by treating
|
|
176
|
+
# singletons uniformly as `Class` instances.
|
|
177
|
+
#
|
|
178
|
+
# The approximation answers through `Class`, so a target `Class` cannot be ordered against — a
|
|
179
|
+
# project module, typically — lands on the same `:unknown` #657 collapsed to `Bot`, and `case Widget
|
|
180
|
+
# when Meta` was reported unreachable where `Widget` had `extend Meta`.
|
|
181
|
+
#
|
|
182
|
+
# Issue #898 — that decline is silent about a target the environment DOES order against `Class`, and
|
|
183
|
+
# `extend Comparable` is one: both names are in RBS, neither includes the other, so the ordering says
|
|
184
|
+
# `:disjoint` and the collapse fired on an arm MRI takes (`Widget.is_a?(Comparable)` is true — the
|
|
185
|
+
# `extend` put `Comparable` in `Widget`'s SINGLETON ancestry, which asking about `Class` cannot see).
|
|
186
|
+
# {#singleton_extend_declines_bot?} supplies the missing half from the project's own `extend` record.
|
|
187
|
+
def narrow_singleton_to_class(singleton, class_name, context)
|
|
188
|
+
return singleton if subclass_of?("Class", class_name, context)
|
|
189
|
+
return Type::Combinator.untyped if declines_bot?("Class", class_name, context)
|
|
190
|
+
return Type::Combinator.untyped if singleton_extend_declines_bot?(singleton, class_name, context)
|
|
191
|
+
|
|
192
|
+
Type::Combinator.bot
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# Whether the class object's own `extend` record forbids the `Bot` the `Class` approximation would
|
|
196
|
+
# otherwise authorise (#898). An extended `M` puts every ancestor of `M` in the singleton's
|
|
197
|
+
# ancestry, so the question per extended module is `M <= target`: `:equal` (`extend Comparable`
|
|
198
|
+
# under `when Comparable`) and `:subclass` support the arm, and `:unknown` (`extend Meta` under
|
|
199
|
+
# `when Comparable`, `Meta` being project source the environment never joined to RBS) cannot rule
|
|
200
|
+
# it out. `:superclass` and `:disjoint` support NOTHING and must keep the collapse — `Integer`
|
|
201
|
+
# under `when Integer` orders `:superclass` against an extended `Comparable`, and reading that as
|
|
202
|
+
# support would retract `case Widget when Integer` from every class that extends a core module.
|
|
203
|
+
#
|
|
204
|
+
# The answer is `Dynamic[top]`, never the preserved `Singleton[C]`, and the negative edge
|
|
205
|
+
# ({#narrow_singleton_not_class}) is untouched — so this record is read ONLY to withhold a claim,
|
|
206
|
+
# never to make one. That asymmetry is deliberate, and it is what keeps the fix honest against an
|
|
207
|
+
# extend record that is structurally incomplete: `Widget.extend(m)` at a call site and an `extend`
|
|
208
|
+
# written in a file outside the analysed set are both invisible to the walk behind
|
|
209
|
+
# {Scope#singleton_extends_of}, and the declaration-side record joined to it below is no more
|
|
210
|
+
# complete — RBS says nothing about a class it does not declare. A shape that turned this table
|
|
211
|
+
# into a positive `:subclass` verdict would have to be right about ABSENCE too, and it cannot be. Preserving
|
|
212
|
+
# `Singleton[C]` would also hand the arm a receiver whose singleton method table has no `clamp` on
|
|
213
|
+
# it, trading the unreachable-clause false positive for an undefined-method one — the same trap
|
|
214
|
+
# #657 recorded on the `Constant` carrier.
|
|
215
|
+
#
|
|
216
|
+
# Issue #915 — two sources, read as one. The source record above sees only what Ruby source spells;
|
|
217
|
+
# a project that declares `extend M` in its own `sig/` puts the same module in the same singleton
|
|
218
|
+
# ancestry, and the environment's declaration-side answer
|
|
219
|
+
# ({Environment#singleton_extended_modules}) is consulted alongside it. Neither is asked to be
|
|
220
|
+
# complete; each can only add a module that IS there, which is all the one-directional read needs.
|
|
221
|
+
def singleton_extend_declines_bot?(singleton, class_name, context)
|
|
222
|
+
return false if context.exact
|
|
223
|
+
|
|
224
|
+
extended = singleton_ancestor_modules(singleton, context)
|
|
225
|
+
return false if extended.empty?
|
|
226
|
+
|
|
227
|
+
extended.any? do |module_name|
|
|
228
|
+
%i[equal subclass unknown].include?(class_ordering(module_name, class_name, context))
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
def singleton_ancestor_modules(singleton, context)
|
|
233
|
+
scope = context.scope
|
|
234
|
+
from_source = scope.nil? ? [] : scope.singleton_extends_of(singleton.class_name)
|
|
235
|
+
from_rbs = context.environment&.singleton_extended_modules(singleton.class_name) || []
|
|
236
|
+
return from_source if from_rbs.empty?
|
|
237
|
+
return from_rbs if from_source.empty?
|
|
238
|
+
|
|
239
|
+
from_source | from_rbs
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
def narrow_singleton_not_class(singleton, class_name, context)
|
|
243
|
+
subclass_of?("Class", class_name, context) ? Type::Combinator.bot : singleton
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
# Top/Dynamic narrow to `Nominal[class_name]` so dispatch can resolve through the asked
|
|
247
|
+
# class; Bot stays Bot.
|
|
248
|
+
def narrow_class_other(type, class_name)
|
|
249
|
+
case type
|
|
250
|
+
when Type::Dynamic, Type::Top then Type::Combinator.nominal_of(class_name)
|
|
251
|
+
else type
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
# Whether the positive edge must decline the `Bot` that `subclass_of?` returning false would
|
|
256
|
+
# otherwise authorise (#657). `subclass_of?` folds `:disjoint` and `:unknown` into one `false`, and
|
|
257
|
+
# only the first is evidence that the guard can never match; the second is the environment saying it
|
|
258
|
+
# cannot tell, which any file reopening either side can make true.
|
|
259
|
+
#
|
|
260
|
+
# This only ever ADDS a decline: every caller keeps its own `subclass_of?` test first, so the
|
|
261
|
+
# preserving edge is untouched, and a `:disjoint`, `:equal`, `:subclass` or `:superclass` verdict
|
|
262
|
+
# never reaches here. There is no ordering it turns INTO a match — the honest answer for
|
|
263
|
+
# "cannot tell" is Dynamic, never the asked class.
|
|
264
|
+
#
|
|
265
|
+
# `instance_of?` is exempt because it compares the exact class: a module is never an object's class,
|
|
266
|
+
# so that edge's `Bot` rests on the guard's own semantics rather than on the ordering.
|
|
267
|
+
def declines_bot?(rigor_class_name, target_class_name, context)
|
|
268
|
+
!context.exact && class_ordering(rigor_class_name, target_class_name, context) == :unknown
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
# Returns `true` when an instance of `rigor_class_name` satisfies
|
|
272
|
+
# `is_a?(target_class_name)` (or `instance_of?(target_class_name)` when `exact: true`).
|
|
273
|
+
# Falls back to the safe `false` when either name does not resolve through the analyzer
|
|
274
|
+
# environment.
|
|
275
|
+
def subclass_of?(rigor_class_name, target_class_name, context)
|
|
276
|
+
return rigor_class_name == target_class_name if context.exact
|
|
277
|
+
|
|
278
|
+
%i[subclass equal].include?(
|
|
279
|
+
class_ordering(rigor_class_name, target_class_name, context)
|
|
280
|
+
)
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
# Compares two class names through the analyzer environment. Returns `:equal` when they
|
|
284
|
+
# resolve to the same class, `:subclass` when `lhs <= rhs`, `:superclass` when `rhs <=
|
|
285
|
+
# lhs`, `:disjoint` when neither, and `:unknown` when either name does not resolve.
|
|
286
|
+
def class_ordering(lhs, rhs, context)
|
|
287
|
+
return :equal if lhs == rhs
|
|
288
|
+
|
|
289
|
+
context.environment.class_ordering(lhs, rhs)
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
private_class_method :narrow_constant_class, :narrow_nominal_class, :narrow_union_class, :narrow_shape_class,
|
|
293
|
+
:narrow_singleton_class, :narrow_other_class, :narrow_constant_to_class,
|
|
294
|
+
:narrow_constant_not_class, :narrow_nominal_to_class, :exact_nominal_to_class,
|
|
295
|
+
:narrow_nominal_not_class, :narrow_shape_to_class, :narrow_shape_not_class,
|
|
296
|
+
:narrow_singleton_to_class, :singleton_extend_declines_bot?, :singleton_ancestor_modules,
|
|
297
|
+
:narrow_singleton_not_class, :narrow_class_other, :declines_bot?, :subclass_of?,
|
|
298
|
+
:class_ordering
|
|
299
|
+
end
|
|
300
|
+
end
|
|
301
|
+
end
|
|
302
|
+
end
|