Class: TypedRb::Model::TmIfElse

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

Instance Attribute Summary collapse

Attributes inherited from Expr

#col, #line, #node, #type

Instance Method Summary collapse

Constructor Details

#initialize(node, condition_expr, then_expr, else_expr) ⇒ TmIfElse

Returns a new instance of TmIfElse.



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

def initialize(node, condition_expr, then_expr, else_expr)
  super(node, nil)
  @condition_expr = condition_expr
  @then_expr = then_expr || Types::TyUnit.new
  @else_expr = else_expr || Types::TyUnit.new
end

Instance Attribute Details

#condition_exprObject (readonly)

Returns the value of attribute condition_expr.



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

def condition_expr
  @condition_expr
end

#else_exprObject

Returns the value of attribute else_expr.



8
9
10
# File 'lib/typed/model/tm_if_else.rb', line 8

def else_expr
  @else_expr
end

#then_exprObject (readonly)

Returns the value of attribute then_expr.



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

def then_expr
  @then_expr
end

Instance Method Details

#check_type(context) ⇒ Object



16
17
18
19
20
21
# File 'lib/typed/model/tm_if_else.rb', line 16

def check_type(context)
  either_type = Types::TyEither.new(node)
  either_type.compatible_either?(then_expr.check_type(context))
  either_type.compatible_either?(else_expr.check_type(context))
  either_type.has_jump? ? either_type : either_type[:normal]
end