trait FullParameterization

Provides methods to produce fully parameterized versions of instance methods, where the this of the enclosing class is abstracted out in an extra leading $this parameter and type parameters of the class become additional type parameters of the fully parameterized method.

Example usage scenarios are:

  • extension methods of value classes
  • implementations of trait methods
  • static protected accessors
  • local methods produced by tailrec transform

Note that the methods lift out type parameters of the class containing the instance method, but not type parameters of enclosing classes. The fully instantiated method therefore needs to be put in a scope "close" to the original method, i.e. they need to share the same outer pointer. Examples of legal positions are: in the companion object, or as a local method inside the original method.

Note: The scheme does not handle yet methods where type parameter bounds depend on value parameters of the enclosing class, as in:

class C(val a: String) extends AnyVal {
  def foo[U <: a.type]: Unit = ...
}

The expansion of method foo would lead to

def foo$extension[U <: $this.a.type]($this: C): Unit = ...

which is not typable. Not clear yet what to do. Maybe allow PolyTypes to follow method parameters and translate to the following:

def foo$extension($this: C)[U <: $this.a.type]: Unit = ...

Constructors

Members

[+] private def allInstanceTypeParams ( originalDef: DefDef , abstractOverClass: Boolean ) ( implicit ctx: Context ) : List [ Symbol ]

The type parameters (skolems) of the method definition originalDef, followed by the class parameters of its enclosing class.

The type parameters (skolems) of the method definition originalDef, followed by the class parameters of its enclosing class.

[+] def forwarder ( derived: TermSymbol , originalDef: DefDef , abstractOverClass: Boolean , liftThisType: Boolean ) ( implicit ctx: Context ) : Tree

A forwarder expression which calls derived, passing along - if abstractOverClass the type parameters and enclosing class parameters of originalDef, - t...

A forwarder expression which calls derived, passing along - if abstractOverClass the type parameters and enclosing class parameters of originalDef, - thethisof the enclosing class, - the value parameters of the original methodoriginalDef`.

[+] def forwarder$default$3 : Boolean

A forwarder expression which calls derived, passing along - if abstractOverClass the type parameters and enclosing class parameters of originalDef, - t...

A forwarder expression which calls derived, passing along - if abstractOverClass the type parameters and enclosing class parameters of originalDef, - thethisof the enclosing class, - the value parameters of the original methodoriginalDef`.

[+] def forwarder$default$4 : Boolean

A forwarder expression which calls derived, passing along - if abstractOverClass the type parameters and enclosing class parameters of originalDef, - t...

A forwarder expression which calls derived, passing along - if abstractOverClass the type parameters and enclosing class parameters of originalDef, - thethisof the enclosing class, - the value parameters of the original methodoriginalDef`.

[+] def fullyParameterizedDef ( derived: TermSymbol , originalDef: DefDef , abstractOverClass: Boolean ) ( implicit ctx: Context ) : Tree

Given an instance method definition originalDef, return a fully parameterized method definition derived from originalDef, which has derived as symbol an...

Given an instance method definition originalDef, return a fully parameterized method definition derived from originalDef, which has derived as symbol and fullyParameterizedType(originalDef.symbol.info) as info. abstractOverClass defines weather the DefDef should abstract over type parameters of class that contained original defDef

[+] def fullyParameterizedDef$default$3 : Boolean

Given an instance method definition originalDef, return a fully parameterized method definition derived from originalDef, which has derived as symbol an...

Given an instance method definition originalDef, return a fully parameterized method definition derived from originalDef, which has derived as symbol and fullyParameterizedType(originalDef.symbol.info) as info. abstractOverClass defines weather the DefDef should abstract over type parameters of class that contained original defDef

[+] def fullyParameterizedType ( info: Type , clazz: ClassSymbol , abstractOverClass: Boolean , liftThisType: Boolean ) ( implicit ctx: Context ) : Type

Converts the type info of a member of class clazz to a method type that takes the this of the class and any type parameters of the class as additional p...

[+A <: AnyRef][A] [B >: A][B]

[B >: A <: Any, A >: Nothing <: AnyRef][A][B]

Converts the type info of a member of class clazz to a method type that takes the this of the class and any type parameters of the class as additional parameters. Example:

class Foo[+A <: AnyRef](val xs: List[A]) extends AnyVal { def baz[B >: A](x: B): List[B] = ... }

leads to:

object Foo { def extension$baz[B >: A <: Any, A >: Nothing <: AnyRef]($this: Foo[A])(x: B): List[B] }

If a self type is present, $this has this self type as its type.

[+] def fullyParameterizedType$default$3 : Boolean

Converts the type info of a member of class clazz to a method type that takes the this of the class and any type parameters of the class as additional p...

[+A <: AnyRef][A] [B >: A][B]

[B >: A <: Any, A >: Nothing <: AnyRef][A][B]

Converts the type info of a member of class clazz to a method type that takes the this of the class and any type parameters of the class as additional parameters. Example:

class Foo[+A <: AnyRef](val xs: List[A]) extends AnyVal { def baz[B >: A](x: B): List[B] = ... }

leads to:

object Foo { def extension$baz[B >: A <: Any, A >: Nothing <: AnyRef]($this: Foo[A])(x: B): List[B] }

If a self type is present, $this has this self type as its type.

[+] def fullyParameterizedType$default$4 : Boolean

Converts the type info of a member of class clazz to a method type that takes the this of the class and any type parameters of the class as additional p...

[+A <: AnyRef][A] [B >: A][B]

[B >: A <: Any, A >: Nothing <: AnyRef][A][B]

Converts the type info of a member of class clazz to a method type that takes the this of the class and any type parameters of the class as additional parameters. Example:

class Foo[+A <: AnyRef](val xs: List[A]) extends AnyVal { def baz[B >: A](x: B): List[B] = ... }

leads to:

object Foo { def extension$baz[B >: A <: Any, A >: Nothing <: AnyRef]($this: Foo[A])(x: B): List[B] }

If a self type is present, $this has this self type as its type.

[+] protected def rewiredTarget ( referenced: Symbol , derived: Symbol ) ( implicit ctx: Context ) : Symbol

If references to original symbol referenced from within fully parameterized method derived should be rewired to some fully parameterized method, the re...

If references to original symbol referenced from within fully parameterized method derived should be rewired to some fully parameterized method, the rewiring target symbol, otherwise NoSymbol.

[+] protected def rewiredTarget ( tree: Tree , derived: Symbol ) ( implicit ctx: Context ) : Symbol

If references to some original symbol from given tree node within fully parameterized method derived should be rewired to some fully parameterized meth...

rewiredTarget(tree.symbol, derived)

If references to some original symbol from given tree node within fully parameterized method derived should be rewired to some fully parameterized method, the rewiring target symbol, otherwise NoSymbol. By default implemented as

rewiredTarget(tree.symbol, derived)

but can be overridden.