class TypedRb::Model::TmInstanceVarAssignment

instance variable assignation

Attributes

lvalue[RW]
rvalue[RW]

Public Class Methods

new(lvalue, rvalue, node) click to toggle source
Calls superclass method TypedRb::Model::Expr::new
# File lib/typed/model/tm_instance_var_assignment.rb, line 9
def initialize(lvalue, rvalue, node)
  super(node)
  @lvalue = lvalue
  @rvalue = rvalue
end

Public Instance Methods

check_type(context) click to toggle source
# File lib/typed/model/tm_instance_var_assignment.rb, line 15
def check_type(context)
  rvalue_type = rvalue.check_type(context)
  self_type = context.get_type_for(:self)
  lvalue_type = self_type.find_var_type(lvalue.val)
  if lvalue_type.nil?
    fail TypeCheckError.new("Error type checking instance variable #{lvalue} assignment: Cannot find type for variable", node)
  end
  if lvalue_type.compatible?(rvalue_type, :gt)
    rvalue_type
  else
    error_message = "Error type checking instance variable #{lvalue} assignment: Error finding compatible instance variable, expected #{lvalue_type} found #{rvalue_type}"
    fail TypeCheckError.new(error_message, node)
  end
end