Class: Mirah::AST::RequiredArgument

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

Instance Attribute Summary

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

#containing_scope, #scope

Methods included from Named

#string_value, #to_s, #validate_name

Methods inherited from Argument

#resolved!

Methods inherited from Node

#<<, ===, #[], #[]=, #_dump, _load, #_set_parent, child, child_name, #child_nodes, #each, #empty?, #expr?, #inferred_type!, #initialize_copy, #insert, #inspect, #inspect_children, #line_number, #log, #precompile, #resolve_if, #resolved!, #resolved?, #simple_name, #string_value, #temp, #to_s, #top_level?, #validate_child, #validate_children

Constructor Details

#initialize(parent, line_number, name, type = nil) ⇒ RequiredArgument

Returns a new instance of RequiredArgument.



115
116
117
118
119
# File 'lib/mirah/ast/method.rb', line 115

def initialize(parent, line_number, name, type=nil)
  super(parent, line_number, [type])

  self.name = name
end

Instance Method Details

#infer(typer, expression) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/mirah/ast/method.rb', line 121

def infer(typer, expression)
  resolve_if(typer) do
    scope.static_scope << name
    # if not already typed, check parent of parent (MethodDefinition)
    # for signature info
    method_def = parent.parent
    signature = method_def.signature

    if type_node
      if ::String === type_node  # How does this happen?
        signature[name.intern] = typer.type_reference(scope, type_node)
      else
        signature[name.intern] = type_node.type_reference(typer)
      end
    end

    # if signature, search for this argument
    signature[name.intern] || typer.local_type(containing_scope, name)
  end
end

#validate_type_nodeObject



142
143
144
145
146
# File 'lib/mirah/ast/method.rb', line 142

def validate_type_node
  if UnquotedValue === type_node
    self.type_node = type_node.type
  end
end