Class: Duby::AST::RequiredArgument

Inherits:
Argument show all
Includes:
Named, Scoped
Defined in:
lib/duby/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

#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) ⇒ RequiredArgument

Returns a new instance of RequiredArgument.



25
26
27
28
29
# File 'lib/duby/ast/method.rb', line 25

def initialize(parent, line_number, name)
  super(parent, line_number)

  @name = name
end

Instance Method Details

#infer(typer) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/duby/ast/method.rb', line 31

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
    if signature[name.intern]
      @inferred_type = typer.learn_local_type(scope, name, signature[name.intern])
    else
      @inferred_type = typer.local_type(scope, name)
    end
      
    unless @inferred_type
      typer.defer(self)
    end
  end
    
  @inferred_type
end