Class: Rigor::Inference::MethodParameterBinder

Inherits:
Object
  • Object
show all
Defined in:
lib/rigor/inference/method_parameter_binder.rb,
sig/rigor/inference.rbs

Instance Method Summary collapse

Constructor Details

#initialize(environment:, class_path:, singleton:, source_path: nil) ⇒ MethodParameterBinder

Returns a new instance of MethodParameterBinder.

Parameters:

  • environment (Rigor::Environment)
  • class_path (String, nil)

    the qualified name of the class the method is defined in (e.g., "Foo::Bar"), or nil for a top-level def outside any class. When nil (or when the class is unknown to RBS), every parameter falls back to Dynamic[Top].

  • singleton (Boolean)

    true when the def is a singleton method (either def self.foo or a def foo inside class << self); routes the lookup through RbsLoader#singleton_method.

  • source_path (String, nil) (defaults to: nil)

    the project-relative path of the file the method is defined in. Used to match ADR-28 path-scoped protocol contracts; nil (the default for synthetic / probe scopes) disables the contract tier.

  • environment: (Environment)
  • class_path: (String)
  • singleton: (Boolean)


68
69
70
71
72
73
# File 'lib/rigor/inference/method_parameter_binder.rb', line 68

def initialize(environment:, class_path:, singleton:, source_path: nil)
  @environment = environment
  @class_path = class_path
  @singleton = singleton
  @source_path = source_path
end

Instance Method Details

#bind(def_node) ⇒ Hash{Symbol => Rigor::Type}

Returns ordered map from parameter name to bound type. Anonymous parameters (* and ** without a name) are skipped.

Parameters:

  • def_node (Prism::DefNode)

Returns:

  • (Hash{Symbol => Rigor::Type})

    ordered map from parameter name to bound type. Anonymous parameters (* and ** without a name) are skipped.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/rigor/inference/method_parameter_binder.rb', line 78

def bind(def_node)
  slots = collect_slots(def_node.parameters)
  types = default_types_for(slots)

  rbs_method = lookup_rbs_method(def_node)
  if rbs_method
    apply_rbs_overloads(types, slots, rbs_method.method_types) unless rbs_method.method_types.empty?
    # `rigor:v1:param: <name> <refinement>` annotations tighten the bound type for matching
    # slots. Applied after the RBS-overload pass so the override is the authoritative
    # answer regardless of what the RBS signature declared.
    apply_param_overrides(types, slots, rbs_method)
  end
  # ADR-28 — a path-scoped protocol contract supplies the parameter type for a matching
  # `def`. Applied last (most authoritative) and regardless of RBS presence: the methods a
  # contract targets — controller actions and the like — typically have no RBS signature
  # at all, so this tier must run even when `rbs_method` is nil.
  apply_protocol_contract(types, slots, def_node)
  types
end