Module: Yoda::Typing::Tree::MethodInferable

Included in:
MethodDef, SingletonMethodDef
Defined in:
lib/yoda/typing/tree/method_inferable.rb

Instance Method Summary collapse

Instance Method Details

#body_nodeAST::ParametersNode

This method is abstract.

Returns:



45
46
47
# File 'lib/yoda/typing/tree/method_inferable.rb', line 45

def body_node
  fail NotImplementedError
end

#infer_method_type(receiver_type:) ⇒ Types::Type

Parameters:

Returns:



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/yoda/typing/tree/method_inferable.rb', line 7

def infer_method_type(receiver_type:)
  value_resolve_context = generator.value_resolve_context(self_type: receiver_type)

  method_candidates = receiver_type.value.select_method(node_name.to_s, visibility: %i(private protected public))
  method_types = method_candidates.map(&:rbs_type).map { |type| value_resolve_context.wrap(type) }

  # TODO: Support overloads
  method_bind = method_types.reduce({}) do |all_bind, method_type|
    bind = Inferencer::ParameterBinder.new(parameters_node.parameter).bind(type: method_type, generator: generator)
    all_bind.merge(bind.to_h) { |_key, v1, v2| generator.union_type(v1, v2) }
  end

  Logger.trace("method_candidates: [#{method_candidates.join(', ')}]")
  Logger.trace("bind arguments: #{method_bind.map { |key, value| [key, value.to_s] }.to_h }")

  bind_method_definition(node: node, method_candidates: method_candidates)

  method_context = context.derive_method_context(receiver_type: receiver_type, binds: method_bind)

  infer_child(body_node, context: method_context)

  generator.symbol_type(node_name.to_sym)
end

#node_nameSymbol, string

This method is abstract.

Returns:

  • (Symbol, string)


33
34
35
# File 'lib/yoda/typing/tree/method_inferable.rb', line 33

def node_name
  fail NotImplementedError
end

#parameters_nodeAST::ParametersNode

This method is abstract.

Returns:



39
40
41
# File 'lib/yoda/typing/tree/method_inferable.rb', line 39

def parameters_node
  fail NotImplementedError
end