Class: Yoda::Typing::Tree::RescueClause

Inherits:
Base
  • Object
show all
Defined in:
lib/yoda/typing/tree/rescue_clause.rb

Instance Attribute Summary

Attributes inherited from Base

#context, #tracer

Instance Method Summary collapse

Methods inherited from Base

#build_child, #generator, #infer_child, #initialize, #inspect, #pretty_print, #type

Constructor Details

This class inherits a constructor from Yoda::Typing::Tree::Base

Instance Method Details

#infer_typeTypes::Type

Returns:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/yoda/typing/tree/rescue_clause.rb', line 9

def infer_type
  binds = {}

  exception_type = begin
    if node.match_clause
      case node.match_clause.type
      when :array
        generator.union_type(*node.match_clause.contents.map { |content| infer_child(content).instance_type })
      when :empty
        generator.standard_error_type
      else
        # Unexpected
        generator.standard_error_type
      end
    else
      generator.standard_error_type
    end
  end


  if node.assignee
    case node.assignee.type
    when :lvasgn
      binds[node.assignee.assignee.name] = exception_type
    end
  end

  new_context = context.derive_block_context(binds: binds)
  infer_child(node.body, context: new_context)
end

#nodeAST::RescueClauseNode



# File 'lib/yoda/typing/tree/rescue_clause.rb', line 5