Class: Duby::AST::RescueClause

Inherits:
Node show all
Includes:
Scoped
Defined in:
lib/duby/ast/flow.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#children, #inferred_type, #newline, #parent, #position

Instance Method Summary collapse

Methods included from Scoped

#scope

Methods inherited from Node

#[], #each, #expr?, #inspect, #line_number, #log, #precompile, #resolve_if, #resolved!, #resolved?, #simple_name, #temp, #to_s

Constructor Details

#initialize(parent, position, &block) ⇒ RescueClause

Returns a new instance of RescueClause.



262
263
264
265
# File 'lib/duby/ast/flow.rb', line 262

def initialize(parent, position, &block)
  super(parent, position, &block)
  @types, @body = children
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



260
261
262
# File 'lib/duby/ast/flow.rb', line 260

def body
  @body
end

#nameObject

Returns the value of attribute name.



260
261
262
# File 'lib/duby/ast/flow.rb', line 260

def name
  @name
end

#typeObject

Returns the value of attribute type.



260
261
262
# File 'lib/duby/ast/flow.rb', line 260

def type
  @type
end

#typesObject

Returns the value of attribute types.



260
261
262
# File 'lib/duby/ast/flow.rb', line 260

def types
  @types
end

Instance Method Details

#infer(typer) ⇒ Object



267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/duby/ast/flow.rb', line 267

def infer(typer)
  unless resolved?
    if name
      orig_type = typer.local_type(scope, name)
      # TODO find the common parent Throwable
      @type = types.size == 1 ? types[0] : AST.type('java.lang.Throwable')
      typer.learn_local_type(scope, name, @type)
    end
    @inferred_type = typer.infer(body)

    (@inferred_type && body.resolved?) ? resolved! : typer.defer(self)
    typer.local_type_hash(scope)[name] = orig_type if name
  end

  @inferred_type
end