Trees

object Trees
class Object
trait Matchable
class Any

Type members

Classlikes

case class Alternative[-T >: Untyped] extends PatternTree[T]

tree_1 | ... | tree_n

tree_1 | ... | tree_n

case class Annotated[-T >: Untyped] extends ProxyTree[T]

arg @annot

arg @annot

case class AppliedTypeTree[-T >: Untyped] extends ProxyTree[T] with TypTree[T]

tpt[args]

tpt[args]

case class Apply[-T >: Untyped] extends GenericApply[T]

fun(args)

fun(args)

enum ApplyKind

The kind of application

The kind of application

case class Assign[-T >: Untyped] extends TermTree[T]

name = arg, outside a parameter list

name = arg, outside a parameter list

case class Bind[-T >: Untyped] extends NamedDefTree[T] with PatternTree[T]

name @ body

name @ body

case class Block[-T >: Untyped] extends Tree[T]

{ stats; expr }

{ stats; expr }

case class ByNameTypeTree[-T >: Untyped] extends TypTree[T]

=> T

=> T

case class CaseDef[-T >: Untyped] extends Tree[T]

case pat if guard => body; only appears as child of a Match

case pat if guard => body; only appears as child of a Match

case class Closure[-T >: Untyped] extends TermTree[T]

A closure with an environment and a reference to a method.

A closure with an environment and a reference to a method.

Value Params
env

The captured parameters of the closure

meth

A ref tree that refers to the method of the closure. The first (env.length) parameters of that method are filled with env values.

tpt

Either EmptyTree or a TypeTree. If tpt is EmptyTree the type of the closure is a function type, otherwise it is the type given in tpt, which must be a SAM type.

case class DefDef[-T >: Untyped] extends ValOrDefDef[T]

mods def nametparams...(vparams_n): tpt = rhs

mods def nametparams...(vparams_n): tpt = rhs

trait DefTree[-T >: Untyped] extends DenotingTree[T]

Tree defines a new symbol

Tree defines a new symbol

abstract class DenotingTree[-T >: Untyped](implicit @constructorOnly src: SourceFile) extends Tree[T]

Tree's denotation can be derived from its type

Tree's denotation can be derived from its type

class EmptyTree[T >: Untyped] extends Thicket[Any]
class EmptyValDef[T >: Untyped] extends ValDef[T] with WithoutTypeOrPos[T]
case class Export[-T >: Untyped] extends ImportOrExport[T]

export expr.selectors where a selector is either an untyped Ident, name or an untyped thicket consisting of name and rename.

export expr.selectors where a selector is either an untyped Ident, name or an untyped thicket consisting of name and rename.

abstract class GenericApply[-T >: Untyped](implicit @constructorOnly src: SourceFile) extends ProxyTree[T] with TermTree[T]
case class Ident[-T >: Untyped] extends RefTree[T]

name

name

case class If[-T >: Untyped] extends TermTree[T]

if cond then thenp else elsep

if cond then thenp else elsep

case class Import[-T >: Untyped] extends ImportOrExport[T]

import expr.selectors where a selector is either an untyped Ident, name or an untyped thicket consisting of name and rename.

import expr.selectors where a selector is either an untyped Ident, name or an untyped thicket consisting of name and rename.

abstract class ImportOrExport[-T >: Untyped](implicit @constructorOnly src: SourceFile) extends DenotingTree[T]
class InlineIf[-T >: Untyped] extends If[T]
class InlineMatch[-T >: Untyped] extends Match[T]
case class Inlined[-T >: Untyped] extends Tree[T]

A tree representing inlined code.

A tree representing inlined code.

Value Params
bindings

Bindings for proxies to be used in the inlined code

call

Info about the original call that was inlined Until PostTyper, this is the full call, afterwards only a reference to the toplevel class from which the call was inlined.

expansion

The inlined tree, minus bindings. The full inlined code is equivalent to { bindings; expansion } The reason to keep bindings separate is because they are typed in a different context: bindings represent the arguments to the inlined call, whereas expansion represents the body of the inlined function.

abstract class Instance[T >: Untyped <: Type]
class JavaSeqLiteral[-T >: Untyped] extends SeqLiteral[T]

Array(elems)

Array(elems)

case class Labeled[-T >: Untyped] extends NameTree[T]

label[tpt]: { expr }

label[tpt]: { expr }

case class LambdaTypeTree[-T >: Untyped] extends TypTree[T]

[typeparams] -> tpt

[typeparams] -> tpt

Note: the type of such a tree is not necessarily a HKTypeLambda, it can also be a TypeBounds where the upper bound is an HKTypeLambda, and the lower bound is either a reference to Nothing or an HKTypeLambda, this happens because these trees are typed by HKTypeLambda#fromParams which makes sure to move bounds outside of the type lambda itself to simplify their handling in the compiler.

You may ask: why not normalize the trees too? That way,

LambdaTypeTree(X, TypeBoundsTree(A, B))

would become,

TypeBoundsTree(LambdaTypeTree(X, A), LambdaTypeTree(X, B))

which would maintain consistency between a tree and its type. The problem with this definition is that the same tree X appears twice, therefore we'd have to create two symbols for it which makes it harder to relate the source code written by the user with the trees used by the compiler (for example, to make "find all references" work in the IDE).

trait Lazy[+T <: AnyRef]

A base trait for lazy tree fields. These can be instantiated with Lazy instances which can delay tree construction until the field is first demanded.

A base trait for lazy tree fields. These can be instantiated with Lazy instances which can delay tree construction until the field is first demanded.

case class Literal[-T >: Untyped] extends Tree[T] with TermTree[T]

const

const

case class Match[-T >: Untyped] extends TermTree[T]

selector match { cases }

selector match { cases }

case class MatchTypeTree[-T >: Untyped] extends TypTree[T]

[bound] selector match { cases }

[bound] selector match { cases }

abstract class MemberDef[-T >: Untyped](implicit @constructorOnly src: SourceFile) extends NamedDefTree[T]

Tree defines a new symbol and carries modifiers. The position of a MemberDef contains only the defined identifier or pattern. The envelope of a MemberDef contains the whole definition and has its point on the opening keyword (or the next token after that if keyword is missing).

Tree defines a new symbol and carries modifiers. The position of a MemberDef contains only the defined identifier or pattern. The envelope of a MemberDef contains the whole definition and has its point on the opening keyword (or the next token after that if keyword is missing).

abstract class NameTree[-T >: Untyped](implicit @constructorOnly src: SourceFile) extends DenotingTree[T]

Tree has a name

Tree has a name

case class NamedArg[-T >: Untyped] extends Tree[T]

name = arg, in a parameter list

name = arg, in a parameter list

abstract class NamedDefTree[-T >: Untyped](implicit @constructorOnly src: SourceFile) extends NameTree[T] with DefTree[T]
case class New[-T >: Untyped] extends Tree[T] with TermTree[T]

new tpt, but no constructor call

new tpt, but no constructor call

case class PackageDef[-T >: Untyped] extends ProxyTree[T]

package pid { stats }

package pid { stats }

trait PatternTree[-T >: Untyped] extends Tree[T]

Instances of this class are trees which are not terms but are legal parts of patterns.

Instances of this class are trees which are not terms but are legal parts of patterns.

abstract class ProxyTree[-T >: Untyped](implicit @constructorOnly src: SourceFile) extends Tree[T]

Tree's denot/isType/isTerm properties come from a subtree identified by forwardTo.

Tree's denot/isType/isTerm properties come from a subtree identified by forwardTo.

abstract class RefTree[-T >: Untyped](implicit @constructorOnly src: SourceFile) extends NameTree[T]

Tree refers by name to a denotation

Tree refers by name to a denotation

case class RefinedTypeTree[-T >: Untyped] extends ProxyTree[T] with TypTree[T]

tpt { refinements }

tpt { refinements }

case class Return[-T >: Untyped] extends TermTree[T]

return expr where from refers to the method or label from which the return takes place After program transformations this is not necessarily the enclosing method, because closures can intervene.

return expr where from refers to the method or label from which the return takes place After program transformations this is not necessarily the enclosing method, because closures can intervene.

class SearchFailureIdent[-T >: Untyped] extends Ident[T]
case class Select[-T >: Untyped] extends RefTree[T]

qualifier.name, or qualifier#name, if qualifier is a type

qualifier.name, or qualifier#name, if qualifier is a type

class SelectWithSig[-T >: Untyped] extends Select[T]
case class SeqLiteral[-T >: Untyped] extends Tree[T]

Seq(elems)

Seq(elems)

Value Params
tpt

The element type of the sequence.

case class SingletonTypeTree[-T >: Untyped] extends DenotingTree[T] with TypTree[T]

ref.type

ref.type

case class Super[-T >: Untyped] extends ProxyTree[T] with TermTree[T]

C.super[mix], where qual = C.this

C.super[mix], where qual = C.this

case class Template[-T >: Untyped] extends DefTree[T] with WithLazyField[List[Tree[T]]]

extends parents { self => body }

extends parents { self => body }

Value Params
parentsOrDerived

A list of parents followed by a list of derived classes, if this is of class untpd.DerivingTemplate. Typed templates only have parents.

case class TermLambdaTypeTree[-T >: Untyped] extends TypTree[T]
trait TermTree[-T >: Untyped] extends Tree[T]

Instances of this class are trees for which isTerm is definitely true. Note that some trees have isTerm = true without being TermTrees (e.g. Ident, Annotated)

Instances of this class are trees for which isTerm is definitely true. Note that some trees have isTerm = true without being TermTrees (e.g. Ident, Annotated)

case class Thicket[-T >: Untyped](trees: List[Tree[T]])(implicit @constructorOnly src: SourceFile) extends Tree[T] with WithoutTypeOrPos[T]

Temporary class that results from translation of ModuleDefs (and possibly other statements). The contained trees will be integrated when transformed with a transform(List[Tree]) call.

Temporary class that results from translation of ModuleDefs (and possibly other statements). The contained trees will be integrated when transformed with a transform(List[Tree]) call.

case class This[-T >: Untyped] extends DenotingTree[T] with TermTree[T]

qual.this

qual.this

abstract class Tree[-T >: Untyped](implicit @constructorOnly src: SourceFile) extends Positioned with SrcPos with Product with Container with Showable

Trees take a parameter indicating what the type of their tpe field is. Two choices: Type or Untyped. Untyped trees have type Tree[Untyped].

Trees take a parameter indicating what the type of their tpe field is. Two choices: Type or Untyped. Untyped trees have type Tree[Untyped].

Tree typing uses a copy-on-write implementation:

  • You can never observe a tpe which is null (throws an exception)
  • So when creating a typed tree with withType we can re-use the existing tree transparently, assigning its tpe field, provided it was null before.
  • It is impossible to embed untyped trees in typed ones.
  • Typed trees can be embedded in untyped ones provided they are rooted in a TypedSplice node.
  • Type checking an untyped tree should remove all embedded TypedSplice nodes.
case class Try[-T >: Untyped] extends TermTree[T]

try block catch cases finally finalizer

try block catch cases finally finalizer

trait TypTree[-T >: Untyped] extends Tree[T]

Instances of this class are trees for which isType is definitely true. Note that some trees have isType = true without being TypTrees (e.g. Ident, Annotated)

Instances of this class are trees for which isType is definitely true. Note that some trees have isType = true without being TypTrees (e.g. Ident, Annotated)

case class TypeApply[-T >: Untyped] extends GenericApply[T]

fun[args]

fun[args]

case class TypeBoundsTree[-T >: Untyped] extends TypTree[T]

: lo <: hi : lo <: hi = alias for RHS of bounded opaque type

case class TypeDef[-T >: Untyped] extends MemberDef[T] with ValOrTypeDef[T]

mods class name template or mods trait name template or mods type name = rhs or mods type name >: lo <: hi, if rhs = TypeBoundsTree(lo, hi) or mods type name >: lo <: hi = rhs if rhs = TypeBoundsTree(lo, hi, alias) and opaque in mods

mods class name template or mods trait name template or mods type name = rhs or mods type name >: lo <: hi, if rhs = TypeBoundsTree(lo, hi) or mods type name >: lo <: hi = rhs if rhs = TypeBoundsTree(lo, hi, alias) and opaque in mods

case class TypeTree[-T >: Untyped](implicit @constructorOnly src: SourceFile) extends DenotingTree[T] with TypTree[T]

A type tree that represents an existing or inferred type

A type tree that represents an existing or inferred type

class TypeVarBinder[-T >: Untyped](implicit @constructorOnly src: SourceFile) extends TypeTree[T]

A type tree that defines a new type variable. Its type is always a TypeVar. Every TypeVar is created as the type of one TypeVarBinder.

A type tree that defines a new type variable. Its type is always a TypeVar. Every TypeVar is created as the type of one TypeVarBinder.

case class Typed[-T >: Untyped] extends ProxyTree[T] with TermTree[T]

expr : tpt

expr : tpt

case class UnApply[-T >: Untyped] extends ProxyTree[T] with PatternTree[T]

The typed translation of extractor(patterns) in a pattern. The translation has the following components:

The typed translation of extractor(patterns) in a pattern. The translation has the following components:

Value Params
fun

is extractor.unapply (or, for backwards compatibility, extractor.unapplySeq) possibly with type parameters

implicits

Any implicit parameters passed to the unapply after the selector

patterns

The argument patterns in the pattern match. It is typed with same type as first fun argument Given a match selector sel a pattern UnApply(fun, implicits, patterns) is roughly translated as follows val result = fun(sel)(implicits) if (result.isDefined) "match patterns against result"

case class ValDef[-T >: Untyped] extends ValOrDefDef[T] with ValOrTypeDef[T]

mods val name: tpt = rhs

mods val name: tpt = rhs

abstract class ValOrDefDef[-T >: Untyped](implicit @constructorOnly src: SourceFile) extends MemberDef[T] with WithLazyField[Tree[T]]

A ValDef or DefDef tree

A ValDef or DefDef tree

trait ValOrTypeDef[-T >: Untyped] extends MemberDef[T]
case class WhileDo[-T >: Untyped] extends TermTree[T]

while (cond) { body }

while (cond) { body }

trait WithLazyField[+T <: AnyRef]

A tree that can have a lazy field The field is represented by some private var which is accessed by unforced and force. Forcing the field will set the var to the underlying value.

A tree that can have a lazy field The field is represented by some private var which is accessed by unforced and force. Forcing the field will set the var to the underlying value.

trait WithoutTypeOrPos[-T >: Untyped] extends Tree[T]

Types

type LazyTree[-T >: Untyped] = Tree[T] | Lazy[Tree[T]]
type LazyTreeList[-T >: Untyped] = List[Tree[T]] | Lazy[List[Tree[T]]]
type Untyped = Null

Value members

Concrete methods

def flatten[T >: Untyped](trees: List[Tree[T]]): List[Tree[T]]

Concrete fields

Property key for backquoted identifiers and definitions

Property key for backquoted identifiers and definitions

Property key for trees with documentation strings attached

Property key for trees with documentation strings attached

var ntrees: Int

The total number of created tree nodes, maintained if Stats.enabled

The total number of created tree nodes, maintained if Stats.enabled

Extensions

Extensions

extension (mdef: DefTree)