module T::Generic::TypeStoragePatch

This module intercepts calls to generic type instantiations and type variable definitions. Tapioca stores the data from those calls in a `GenericTypeRegistry` which can then be used to look up the original call details when we are trying to do code generation.

We are interested in the data of the `[]`, `type_member` and `type_template` calls which are all needed to generate good generic information at runtime.

Public Instance Methods

[](*types) click to toggle source
Calls superclass method
# File lib/tapioca/sorbet_ext/generic_name_patch.rb, line 15
def [](*types)
  # `T::Generic#[]` just returns `self`, so let's call and store it.
  constant = super
  # `register_type` method builds and returns an instantiated clone of the generic type
  # so, we just return that from this method as well.
  Tapioca::GenericTypeRegistry.register_type(constant, types)
end
type_member(variance = :invariant, fixed: nil, lower: T.untyped, upper: BasicObject) click to toggle source
# File lib/tapioca/sorbet_ext/generic_name_patch.rb, line 23
def type_member(variance = :invariant, fixed: nil, lower: T.untyped, upper: BasicObject)
  # `T::Generic#type_member` just instantiates a `T::Type::TypeMember` instance and returns it.
  # We use that when registering the type member and then later return it from this method.
  type_member = Tapioca::TypeMember.new(variance, fixed, lower, upper)
  Tapioca::GenericTypeRegistry.register_type_variable(self, type_member)
  type_member
end
type_template(variance = :invariant, fixed: nil, lower: T.untyped, upper: BasicObject) click to toggle source
# File lib/tapioca/sorbet_ext/generic_name_patch.rb, line 31
def type_template(variance = :invariant, fixed: nil, lower: T.untyped, upper: BasicObject)
  # `T::Generic#type_template` just instantiates a `T::Type::TypeTemplate` instance and returns it.
  # We use that when registering the type template and then later return it from this method.
  type_template = Tapioca::TypeTemplate.new(variance, fixed, lower, upper)
  Tapioca::GenericTypeRegistry.register_type_variable(self, type_template)
  type_template
end