Skip to content

class Crystal::TypeParameter
inherits Crystal::Type

For example, given:

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

when we solve Foo(T, Int32) we'll find Foo, and then instantiate it with T being the type parameter T of Bar, and Int32 a regular type variable.

Similarly, when including a generic module inside a generic type, type parameters will be used.

class Baz(T)
  include Enumerable(T) # <- this is TypeParameter T of Foo
end

When instantiating Bar(T) in the first example, for example doing Bar(Char), superclasses and including modules will have type parameters replaced with types given in the instantiation, so Foo(T, Int32) will become Foo(Char, Int32).

Class methods

.new(program, owner : GenericType, name : String)

View source

Methods

#name : String

Returns the name of this type parameter

View source

#owner : Crystal::GenericType

Returns the type that owns this type parameter

View source

#replace_type_parameters(instance)

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

View source

#solve(instance)

View source

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

View source

#unbound?

View source