Skip to content

class Crystal::VirtualType
inherits Crystal::Type

A virtual type represents a type or any of its subclasses. It's created automatically by the compiler when a type is used in a generic argument and it either has subtypes, or it's abstract. A virtual type never exists for a non-abstract type that doesn't have subtypes.

A virtual type is denoted, internally, with a '+' sign following the type.

class Foo
end

class Bar < Foo
end

# Here the compiler actually makes this be [] of Foo+, so the array
# can actually hold a Foo or a Bar, transparently.
ary = [] of Foo

# Here the compiler leaves it as [] of Bar, because Bar has no subclasses.
another = [] of Bar

Included modules

Crystal::ClassVarContainer Crystal::DefInstanceContainer Crystal::InstanceVarContainer Crystal::MultiType Crystal::VirtualTypeLookup

Class methods

.new(program, base_type)

View source

Methods

#abstract?

View source

#abstract?(*args, **options)

View source

#add_subclasses_method_missing_matches(base_type, method_missing, signature, call)

View source

#all_class_vars

View source

#all_instance_vars

View source

#all_instance_vars(*args, **options)

View source

#ancestors

View source

#ancestors(*args, **options)

View source

#append_cover(array)

View source

#base_type : Type

Given Foo+, this returns Foo.

View source

#check_method_missing(signature, call)

View source

#collect_subtypes(type, subtypes)

View source

#common_ancestor(other)

View source

#cover

View source

#cover_size

View source

#each_concrete_type

View source

#each_cover

View source

#implements?

View source

#implements?(*args, **options)

View source

#index_of_instance_var(*args, **options)

View source

#index_of_instance_var

View source

#leaf?

View source

#leaf?(*args, **options)

View source

#lookup_class_var?(name)

View source

#lookup_defs

View source

#lookup_defs(*args, **options)

View source

#lookup_defs_with_modules

View source

#lookup_defs_with_modules(*args, **options)

View source

#lookup_first_def

View source

#lookup_first_def(*args, **options)

View source

#lookup_instance_var(*args, **options)

View source

#lookup_instance_var

View source

#lookup_instance_var?

View source

#lookup_instance_var?(*args, **options)

View source

#lookup_macro

View source

#lookup_macro(*args, **options)

View source

#lookup_macros

View source

#lookup_macros(*args, **options)

View source

#lookup_path

View source

#lookup_path(*args, **options)

View source

#lookup_similar_def(*args, **options)

View source

#lookup_similar_def

View source

#lookup_similar_path(*args, **options)

View source

#lookup_similar_path

View source

#metaclass

Returns this type's metaclass, which holds class methods for this type.

View source

#name

View source

#remove_indirection

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 : Generic, context)

View source

#restrict(other : Type, context)

View source

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

View source

#struct?

View source

#struct?(*args, **options)

View source

#subtypes

View source

#subtypes(type)

View source

#superclass(*args, **options)

View source

#superclass

View source

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

View source

#type_var?

View source

#type_var?(*args, **options)

View source