Dotty Documentation

0.2.0-bin-SNAPSHOT

class ExplicitOuter
extends MiniPhaseTransform with InfoTransformer

This phase adds outer accessors to classes and traits that need them. Compared to Scala 2.x, it tries to minimize the set of classes that take outer accessors by scanning class implementations for outer references.

The following things are delayed until erasure and are performed by class OuterOps:

  • add outer parameters to constructors
  • pass outer arguments in constructor calls

replacement of outer this by outer paths is done in Erasure. needs to run after pattern matcher as it can add outer checks and force creation of $outer

[-] Constructors

ExplicitOuter ( )

[-] Members

[+] val Outer : Key [ Tree ]
[+] override def changesMembers : Boolean

Can this transform create or delete non-private members?

[+] override def mayChange ( sym: Symbol ) ( implicit ctx: Context ) : Boolean

Denotations with a symbol where mayChange is false are guaranteed to be unaffected by this transform, so transformInfo need not be run. This can save time, and more importantly, can help avoid forcing symbol completers.

[+] override def phaseName : String

A name given to the Phase that can be used to debug the compiler. For instance, it is possible to print trees after a given phase using:

$ ./bin/dotc -Xprint:<phaseNameHere> sourceFile.scala
[+] override def runsAfter : Set [ Class [ Nothing <: Phase ] ]

List of names of phases that should have finished their processing of all compilation units before this phase starts

[+] override def transformClosure ( tree: Closure ) ( implicit ctx: Context , info: TransformerInfo ) : Tree
[+] override def transformInfo ( tp: Type , sym: Symbol ) ( implicit ctx: Context ) : Type

Add outer accessors if a class always needs an outer pointer

[+] override def transformSelect ( tree: Select ) ( implicit ctx: Context , info: TransformerInfo ) : Tree

Convert a selection of the form qual.C_<OUTER> to an outer path from qual to C

[+] override def transformTemplate ( impl: Template ) ( implicit ctx: Context , info: TransformerInfo ) : Tree

First, add outer accessors if a class does not have them yet and it references an outer this. If the class has outer accessors, implement them. Furthermore, if a parent trait might have an outer accessor, provide an implementation for the outer accessor by computing the parent's outer from the parent type prefix. If the trait ends up not having an outer accessor after all, the implementation is redundant, but does not harm. The same logic is not done for non-trait parent classes because for them the outer pointer is passed in the super constructor, which will be implemented later in a separate phase which needs to run after erasure. However, we make sure here that the super class constructor is indeed a New, and not just a type.