class TypedRb::Types::TyGenericObject

Public Class Methods

new(ruby_type, type_vars, node = nil) click to toggle source
Calls superclass method
# File lib/typed/types/ty_generic_object.rb, line 13
def initialize(ruby_type, type_vars, node = nil)
  super(ruby_type, node)
  @type_vars = type_vars
end

Public Instance Methods

apply_bindings(bindings_map) click to toggle source
# File lib/typed/types/ty_generic_object.rb, line 53
def apply_bindings(bindings_map)
  type_vars.each_with_index do |var, i|
    if var.is_a?(Polymorphism::TypeVariable)
      var.apply_bindings(bindings_map)
      type_vars[i] = var.bound if var.bound && var.bound.is_a?(Polymorphism::TypeVariable)
    elsif var.is_a?(TyGenericSingletonObject) || var.is_a?(TyGenericObject)
      var.apply_bindings(bindings_map)
    end
  end
  self
end
clone_with_substitutions(substitutions) click to toggle source
# File lib/typed/types/ty_generic_object.rb, line 40
def clone_with_substitutions(substitutions)
  materialized_type_vars = type_vars(recursive: false).map do |type_var|
    if type_var.is_a?(Polymorphism::TypeVariable)
      substitutions[type_var.variable] || type_var.clone
    elsif type_var.is_a?(TyGenericSingletonObject) || type_var.is_a?(TyGenericObject)
      type_var.clone_with_substitutions(substitutions)
    else
      type_var
    end
  end
  self.class.new(ruby_type, materialized_type_vars, node)
end
find_function_type(message, num_args, block) click to toggle source

This object has concrete type parameters The generic Function we retrieve from the registry might be generic If it is generic we apply the bound parameters and we obtain a concrete function type

# File lib/typed/types/ty_generic_object.rb, line 21
def find_function_type(message, num_args, block)
  function_klass_type, function_type = find_function_type_in_hierarchy(:instance, message, num_args, block)
  if function_klass_type != ruby_type && ancestor_of_super_type?(generic_singleton_object.super_type, function_klass_type)
    target_class = ancestor_of_super_type?(generic_singleton_object.super_type, function_klass_type)
    TypedRb.log binding, :debug, "Found message '#{message}', generic function: #{function_type}, explicit super type #{target_class}"
    target_type_vars = target_class.type_vars
    materialize_super_type_found_function(message, num_args, block, target_class, target_type_vars)
  elsif function_klass_type != ruby_type && BasicObject::TypeRegistry.find_generic_type(function_klass_type)
    TypedRb.log binding, :debug, "Found message '#{message}', generic function: #{function_type}, implict super type #{function_klass_type}"
    target_class = BasicObject::TypeRegistry.find_generic_type(function_klass_type)
    materialize_super_type_found_function(message, num_args, block, target_class, type_vars)
  else
    TypedRb.log binding, :debug, "Found message '#{message}', generic function: #{function_type}"
    materialized_function = materialize_found_function(function_type)
    TypedRb.log binding, :debug, "Found message '#{message}', materialized generic function: #{materialized_function}"
    [function_klass_type, materialized_function]
  end
end