Sha256: 947af98f4ad2b49cc537fd9a8c39a553eceb879459f2e3f600243e95db5c0bb5

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

module Yoda
  module Typing
    module Tree
      class RescueClause < Base
        # @!method node
        #   @return [AST::RescueClauseNode]

        # @return [Types::Type]
        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
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
yoda-language-server-0.10.1 lib/yoda/typing/tree/rescue_clause.rb
yoda-language-server-0.10.0 lib/yoda/typing/tree/rescue_clause.rb