Class: TypedRb::Model::TmBooleanOperator
- Defined in:
- lib/typed/model/tm_boolean_operator.rb
Overview
abstraction
Instance Attribute Summary collapse
-
#lhs ⇒ Object
Returns the value of attribute lhs.
-
#operator ⇒ Object
Returns the value of attribute operator.
-
#rhs ⇒ Object
Returns the value of attribute rhs.
Attributes inherited from Expr
Instance Method Summary collapse
- #check_type(context) ⇒ Object
-
#initialize(operator, lhs, rhs, node) ⇒ TmBooleanOperator
constructor
A new instance of TmBooleanOperator.
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
#lhs ⇒ Object
Returns the value of attribute lhs.
7 8 9 |
# File 'lib/typed/model/tm_boolean_operator.rb', line 7 def lhs @lhs end |
#operator ⇒ Object
Returns the value of attribute operator.
7 8 9 |
# File 'lib/typed/model/tm_boolean_operator.rb', line 7 def operator @operator end |
#rhs ⇒ Object
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 |