Class: TypedRb::Model::TmBooleanOperator

Inherits:
Expr show all
Defined in:
lib/typed/model/tm_boolean_operator.rb

Overview

abstraction

Instance Attribute Summary collapse

Attributes inherited from Expr

#col, #line, #node, #type

Instance Method Summary collapse

Constructor Details

#initialize(operator, lhs, rhs, node) ⇒ TmBooleanOperator

Returns a new instance of TmBooleanOperator.



9
10
11
12
13
14
# File 'lib/typed/model/tm_boolean_operator.rb', line 9

def initialize(operator, lhs, rhs, node)
  super(node)
  @lhs = lhs
  @rhs = rhs
  @operator = operator
end

Instance Attribute Details

#lhsObject

Returns the value of attribute lhs.



7
8
9
# File 'lib/typed/model/tm_boolean_operator.rb', line 7

def lhs
  @lhs
end

#operatorObject

Returns the value of attribute operator.



7
8
9
# File 'lib/typed/model/tm_boolean_operator.rb', line 7

def operator
  @operator
end

#rhsObject

Returns the value of attribute rhs.



7
8
9
# File 'lib/typed/model/tm_boolean_operator.rb', line 7

def rhs
  @rhs
end

Instance Method Details

#check_type(context) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/typed/model/tm_boolean_operator.rb', line 16

def check_type(context)
  lhs_type = @lhs.check_type(context)
  rhs_type = @rhs.check_type(context)
  if lhs_type.is_a?(Types::Polymorphism::TypeVariable) || rhs_type.is_a?(Types::Polymorphism::TypeVariable)
    var = Types::TypingContext.local_type_variable
    var.compatible?(lhs_type, :gt)
    var.compatible?(rhs_type, :gt)
    var
  else
    types = [lhs_type, rhs_type].reject { |type| type.is_a?(Types::TyUnit) || type.is_a?(Types::TyError) }
    type = types.reduce(&:max)
    type  = Types::TyUnit.new if type.nil?
    type.node = node
    type
  end
end