Class: TypedRb::Types::TyExistentialType

Inherits:
TyObject show all
Defined in:
lib/typed/types/ty_existential_type.rb

Direct Known Subclasses

TyGenericExistentialType

Instance Attribute Summary collapse

Attributes inherited from TyObject

#classes, #hierarchy, #modules, #ruby_type, #with_ruby_type

Attributes inherited from Type

#node

Instance Method Summary collapse

Methods inherited from TyObject

#<=>, #as_object_type, #check_type, #compatible?, #dynamic?, #either?, #find_function_type, #find_function_type_in_hierarchy, #find_var_type, #generic?, #join, #max, #resolve_ruby_method, #singleton?, #to_s, #union

Methods included from Comparable

#<=>

Methods inherited from Type

#compatible?, #either?, #stack_jump?

Constructor Details

#initialize(ruby_type, node = nil) ⇒ TyExistentialType

Returns a new instance of TyExistentialType.



8
9
10
11
12
13
# File 'lib/typed/types/ty_existential_type.rb', line 8

def initialize(ruby_type, node = nil)
  super(ruby_type, node)
  @hierarchy = [ruby_type] + Module.ancestors
  @classes = @hierarchy.select { |klass| klass.instance_of?(Class) }
  @modules = @hierarchy.select { |klass| klass.instance_of?(Module) }
end

Instance Attribute Details

#local_typing_contextObject

Returns the value of attribute local_typing_context.



6
7
8
# File 'lib/typed/types/ty_existential_type.rb', line 6

def local_typing_context
  @local_typing_context
end

#self_variableObject

Returns the value of attribute self_variable.



6
7
8
# File 'lib/typed/types/ty_existential_type.rb', line 6

def self_variable
  @self_variable
end

Instance Method Details

#check_inclusion(self_type) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/typed/types/ty_existential_type.rb', line 15

def check_inclusion(self_type)
  cloned_context, _ = local_typing_context.clone(:module_self)
  Types::TypingContext.with_context(cloned_context) do
    context_self_type = Types::TypingContext.type_variable_for(ruby_type, :module_self, [ruby_type])
    context_self_type.compatible?(self_type, :lt)
    Types::Polymorphism::Unification.new(Types::TypingContext.all_constraints).run(false)
  end
end