Class: Rigor::Inference::Fallback

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

Overview

Immutable value object recorded by the typer whenever Scope#type_of falls back to Dynamic for a node it does not yet recognise. The contract for emitting these events lives in docs/internal-spec/inference-engine.md (Fail-Soft Policy).

Fields:

  • node_class: the Ruby class of the node that triggered the fallback (e.g. Prism::CallNode, or a Rigor::AST::Node subclass).
  • location: the Prism source location for real Prism nodes, or nil for synthetic nodes.
  • family: :prism for real Prism nodes, :virtual for nodes that include Rigor::AST::Node.
  • inner_type: the Rigor::Type returned to the caller (currently always Dynamic; later slices may carry richer fallback types).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node_class:, location:, family:, inner_type:, origin: nil) ⇒ Fallback

Returns a new instance of Fallback.

Parameters:

  • node_class: (Class)
  • location: (Object)
  • family: (Symbol)
  • inner_type: (Type::t)

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
28
# File 'lib/rigor/inference/fallback.rb', line 20

def initialize(node_class:, location:, family:, inner_type:, origin: nil)
  raise ArgumentError, "node_class must be a Class, got #{node_class.class}" unless node_class.is_a?(Class)

  unless FALLBACK_FAMILIES.include?(family)
    raise ArgumentError, "family must be one of #{FALLBACK_FAMILIES.inspect}, got #{family.inspect}"
  end

  super
end

Instance Attribute Details

#familySymbol (readonly)

Returns the value of attribute family.

Returns:

  • (Symbol)


142
143
144
# File 'sig/rigor/inference.rbs', line 142

def family
  @family
end

#inner_typeType::t (readonly)

Returns the value of attribute inner_type.

Returns:

  • (Type::t)


143
144
145
# File 'sig/rigor/inference.rbs', line 143

def inner_type
  @inner_type
end

#locationObject (readonly)

Returns the value of attribute location.

Returns:

  • (Object)


141
142
143
# File 'sig/rigor/inference.rbs', line 141

def location
  @location
end

#node_classClass (readonly)

Returns the value of attribute node_class.

Returns:

  • (Class)


140
141
142
# File 'sig/rigor/inference.rbs', line 140

def node_class
  @node_class
end