Class: Yoda::Typing::Contexts::BaseContext Abstract

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
ContextDerivation
Defined in:
lib/yoda/typing/contexts/base_context.rb

Overview

This class is abstract.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ContextDerivation

#derive_block_context, #derive_class_context, #derive_method_context

Constructor Details

#initialize(environment:, receiver:, constant_ref:, parent: nil, binds: nil) ⇒ BaseContext

Returns a new instance of BaseContext.

Parameters:

  • environment (Model::Environment)
  • receiver (Types::Type)

    represents who is self of the code.

  • constant_ref (Types::Type)

    represents who is self of the code.

  • parent (BaseContext, nil) (defaults to: nil)
  • binds (Hash{Symbol => RBS::Types::t}, nil) (defaults to: nil)


34
35
36
37
38
39
40
# File 'lib/yoda/typing/contexts/base_context.rb', line 34

def initialize(environment:, receiver:, constant_ref:, parent: nil, binds: nil)
  @environment = environment
  @receiver = receiver
  @constant_ref = constant_ref
  @parent = parent
  @type_binding = Inferencer::TypeBinding.new(parent: parent_variable_scope_context&.type_binding, binds: binds)
end

Instance Attribute Details

#constant_refTypes::Type (readonly)

Returns:



19
20
21
# File 'lib/yoda/typing/contexts/base_context.rb', line 19

def constant_ref
  @constant_ref
end

#environmentModel::Environment (readonly)

Returns:



13
14
15
# File 'lib/yoda/typing/contexts/base_context.rb', line 13

def environment
  @environment
end

#parentBaseContext? (readonly)

Returns:



22
23
24
# File 'lib/yoda/typing/contexts/base_context.rb', line 22

def parent
  @parent
end

#receiverTypes::Type (readonly)

Returns:



16
17
18
# File 'lib/yoda/typing/contexts/base_context.rb', line 16

def receiver
  @receiver
end

#type_bindingInferencer::TypeBinding (readonly)



25
26
27
# File 'lib/yoda/typing/contexts/base_context.rb', line 25

def type_binding
  @type_binding
end

Instance Method Details

#constant_resolverConstantResolver

Returns:



77
78
79
# File 'lib/yoda/typing/contexts/base_context.rb', line 77

def constant_resolver
  ConstantResolver.new(context: self)
end

#generatorTypes::Generator

Returns:



72
73
74
# File 'lib/yoda/typing/contexts/base_context.rb', line 72

def generator
  Types::Generator.new(environment: environment)
end

#lexical_scope_typesArray<Types::Type>

Returns:



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/yoda/typing/contexts/base_context.rb', line 58

def lexical_scope_types
  @lexical_scope_types ||= begin
    parent_types = parent&.lexical_scope_types || []
    if parent.nil?
      [constant_ref]
    elsif parent && constant_ref != parent.constant_ref
      parent_types + [constant_ref]
    else
      parent_types
    end
  end
end

#method_receiverObject



47
48
49
# File 'lib/yoda/typing/contexts/base_context.rb', line 47

def method_receiver
  constant_ref.instance_type
end

#parent_variable_scope_contextContext?

This method is abstract.

Returns:

  • (Context, nil)


53
54
55
# File 'lib/yoda/typing/contexts/base_context.rb', line 53

def parent_variable_scope_context
  fail NotImplementedError
end

#registryObject

Deprecated.

Use methods of Yoda::Typing::Contexts::BaseContext instead.



43
44
45
# File 'lib/yoda/typing/contexts/base_context.rb', line 43

def registry
  environment.registry
end