Dotty Documentation


final class TypeVar
extends CachedProxyType with ValueType

In a TypeApply tree, a TypeVar is created for each argument type to be inferred. Every type variable is referred to by exactly one inferred type parameter of some TypeApply tree.

A type variable is essentially a switch that models some part of a substitution. It is first linked to origin, a poly param that's in the current constraint set. It can then be (once) instantiated to some other type. The instantiation is recorded in the type variable itself, or else, if the current type state is different from the variable's creation state (meaning unrolls are possible) in the current typer state.

[-] Constructors

TypeVar ( _origin: TypeParamRef , creatorState: TyperState )

[-] Members

[+] private var _origin : TypeParamRef
[+] private val creatorState : TyperState
[+] private var myInst : Type

The permanent instance type of the variable, or NoType is none is given yet

[+] var owningState : WeakReference [ TyperState ]

The state owning the variable. This is at first creatorState, but it can be changed to an enclosing state on a commit.

[+] private def _origin_= ( x$1: TypeParamRef ) : Unit
[+] override def computeHash ( bs: Binders ) : Int

Compute hashcode relative to enclosing binders bs

[+] override def equals ( that: Any ) : Boolean
[+] def hasLowerBound ( implicit ctx: Context ) : Boolean

For uninstantiated type variables: Is the lower bound different from Nothing?

[+] def inst : Type
[+] def inst_= ( tp: Type ) : Unit
[+] def instanceOpt ( implicit ctx: Context ) : Type

The instance type of this variable, or NoType if the variable is currently uninstantiated

[+] def instantiate ( fromBelow: Boolean ) ( implicit ctx: Context ) : Type

Instantiate variable from the constraints over its origin. If fromBelow is true, the variable is instantiated to the lub of its lower bounds in the current constraint; otherwise it is instantiated to the glb of its upper bounds. However, a lower bound instantiation can be a singleton type only if the upper bound is also a singleton type.

[+] def instantiateWith ( tp: Type ) ( implicit ctx: Context ) : Type

Instantiate variable with given type

[+] def isInstantiated ( implicit ctx: Context ) : Boolean

Is the variable already instantiated?

[+] def origin : TypeParamRef
[+] def owningState_= ( x$1: WeakReference [ TyperState ] ) : Unit

The state owning the variable. This is at first creatorState, but it can be changed to an enclosing state on a commit.

[+] def setOrigin ( p: TypeParamRef ) : Unit

Set origin to new parameter. Called if we merge two conflicting constraints. See OrderingConstraint#merge, OrderingConstraint#rename

[+] override def stripTypeVar ( implicit ctx: Context ) : Type

Unwrap to instance (if instantiated) or origin (if not), until result is no longer a TypeVar

[+] override def toString : String
[+] override def underlying ( implicit ctx: Context ) : Type

If the variable is instantiated, its instance, otherwise its origin