Class: Rigor::AST::TypeNode
- Inherits:
-
Object
- Object
- Rigor::AST::TypeNode
- Includes:
- Node
- Defined in:
- lib/rigor/ast/type_node.rb,
sig/rigor/ast.rbs
Overview
A virtual node that wraps a Rigor::Type. Allows callers to ask "what would the analyzer infer at this position if the value's type were T?" without constructing a real Prism expression.
Rigor::Scope#type_of(TypeNode.new(t)) MUST return a structurally-equal t. The engine MUST NOT modify or annotate the wrapped type.
Inspired by PHPStan's TypeExpr (a synthetic Expr that returns a specific Type from $scope->getType). The Rigor counterpart is spelled "TypeNode" to align with Prism's "Node" suffix convention.
Instance Attribute Summary collapse
-
#type ⇒ Type::t
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #==(other) ⇒ Boolean (also: #eql?)
- #hash ⇒ Integer
-
#initialize(type) ⇒ TypeNode
constructor
A new instance of TypeNode.
- #inspect ⇒ String
Constructor Details
#initialize(type) ⇒ TypeNode
Returns a new instance of TypeNode.
18 19 20 21 22 23 |
# File 'lib/rigor/ast/type_node.rb', line 18 def initialize(type) raise ArgumentError, "TypeNode requires a non-nil Rigor::Type" if type.nil? @type = type freeze end |
Instance Attribute Details
#type ⇒ Type::t (readonly)
Returns the value of attribute type.
16 17 18 |
# File 'lib/rigor/ast/type_node.rb', line 16 def type @type end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
25 26 27 |
# File 'lib/rigor/ast/type_node.rb', line 25 def ==(other) other.is_a?(TypeNode) && type == other.type end |
#hash ⇒ Integer
30 31 32 |
# File 'lib/rigor/ast/type_node.rb', line 30 def hash [TypeNode, type].hash end |
#inspect ⇒ String
34 35 36 |
# File 'lib/rigor/ast/type_node.rb', line 34 def inspect "#<Rigor::AST::TypeNode #{type.describe(:short)}>" end |