Class: Duby::AST::OptionalArgument

Inherits:
Argument show all
Includes:
Named, Scoped
Defined in:
lib/duby/ast/method.rb

Instance Attribute Summary collapse

Attributes included from Named

#name

Attributes included from Typed

#type

Attributes inherited from Node

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

Instance Method Summary collapse

Methods included from Scoped

#scope

Methods included from Named

#to_s

Methods inherited from Node

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

Constructor Details

#initialize(parent, line_number, name, &block) ⇒ OptionalArgument

Returns a new instance of OptionalArgument.



58
59
60
61
62
# File 'lib/duby/ast/method.rb', line 58

def initialize(parent, line_number, name, &block)
  super(parent, line_number, &block)
  @child = children[0]
  @name = name
end

Instance Attribute Details

#childObject

Returns the value of attribute child.



56
57
58
# File 'lib/duby/ast/method.rb', line 56

def child
  @child
end

Instance Method Details

#infer(typer) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/duby/ast/method.rb', line 64

def infer(typer)
  unless @inferred_type
    # if not already typed, check parent of parent (MethodDefinition) for signature info
    method_def = parent.parent
    signature = method_def.signature

    # if signature, search for this argument
    @inferred_type = child.infer(typer)
    if @inferred_type
      typer.learn_local_type(scope, name, @inferred_type)
      signature[name.intern] = @inferred_type
    else
      typer.defer(self)
    end
  end

  @inferred_type
end