Skip to content

abstract class Crystal::GenericInstanceType
inherits Crystal::Type

An instantiated generic type (like Array(String) or Enumerable(Int32)).

To represent generic superclasses and generic included modules, GenericInstanceType is also used. For example, in:

class Foo(T); end

class Bar(T) < Foo(T); end

The GenericClassType Bar(T) will have a GenericClassInstanceType Foo(T) as a superclass, with T being a TypeParameter. We can't simply have the generic type Foo(T) be the superclass (maybe in this particular example yes) but we could also have:

class Foo(X, Y); end

class Bar(T) < Foo(Int32, T); end

In that case Foo(X, Y) is not quite the superclass, because the superclass has a fixed type Int32 as the first parameter.

Direct known subclasses

Crystal::GenericClassInstanceType Crystal::GenericModuleInstanceType

Class methods

.new(program, generic_type, type_vars)

View source

Methods

#annotation(*args, **options)

View source

#annotation

View source

#annotations(*args, **options)

View source

#annotations

View source

#check_method_missing(*args, **options)

View source

#check_method_missing

View source

#class_var_owner

Returns the type that owns class vars for a type.

This method returns self, but subclasses might override. For example, a metaclass' class_var_owner is the instance type.

View source

#generic_type : GenericType

View source

#has_in_type_vars?(type)

View source

#implements?(other_type)

View source

#lookup_path_item(name : String, lookup_in_namespace, include_private, location)

Looks up a single path item relative to *self`.

If lookup_in_namespace is true, if the type is not found in self or self's parents, the path item is searched in this type's namespace. This parameter is useful because when writing Foo::Bar::Baz, Foo should be searched in enclosing namespaces, but Bar and Baz not.

View source

#parents

View source

#replace_type_parameters(instance)

Replace type parameters in this type with the type parameters of the given instance type.

View source

#restrict(other : GenericInstanceType, context)

View source

#restrict(other : Generic, context)

View source

#restrict(other : GenericType, context)

View source

#restrict_type_var(type_var, other_type_var, context)

View source

#restriction_of?(other : GenericType, owner, strict = false)

View source

#restriction_of?(other : GenericInstanceType, owner, strict = false)

View source

#to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen : Bool = false) : Nil

View source

#type_vars : Hash(String, ASTNode)

View source

#unbound?

View source