SyntheticMembers

dotty.tools.dotc.transform.SyntheticMembers
See theSyntheticMembers companion object

Synthetic method implementations for case classes, case objects, and value classes.

Selectively added to case classes/objects, unless a non-default implementation already exists: def equals(other: Any): Boolean def hashCode(): Int def canEqual(other: Any): Boolean def toString(): String def productElement(i: Int): Any def productArity: Int def productPrefix: String

Add to serializable static objects, unless an implementation already exists: private def writeReplace(): AnyRef

Selectively added to value classes, unless a non-default implementation already exists: def equals(other: Any): Boolean def hashCode(): Int

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

  • If impl is the companion of a generic sum, add deriving.Mirror.Sum parent and MirroredMonoType and ordinal members.
  • If impl is the companion of a generic product, add deriving.Mirror.Product parent and MirroredMonoType and fromProduct members.
  • If impl is marked with one of the attachments ExtendsSingletonMirror or ExtendsSumOfProductMirror, remove the attachment and generate the corresponding mirror support, On this case the represented class or object is referred to in a pre-existing MirroredMonoType member of the template.

Attributes

If this is a case or value class, return the appropriate additional methods, otherwise return nothing.

If this is a case or value class, return the appropriate additional methods, otherwise return nothing.

Attributes

def fromProductBody(caseClass: Symbol, param: Tree, optInfo: Option[OfProduct])(using Context): Tree

The class

The class

case class C[T <: U](x: T, y: String*)

gets the fromProduct method:

def fromProduct(x$0: Product): MirroredMonoType =
  new C[U](
    x$0.productElement(0).asInstanceOf[U],
    x$0.productElement(1).asInstanceOf[Seq[String]]: _*)

where

type MirroredMonoType = C[?]

Attributes

def ordinalBody(cls: Symbol, param: Tree, optInfo: Option[OfSum])(using Context): Tree

For an enum T:

For an enum T:

def ordinal(x: MirroredMonoType) = x.ordinal

For sealed trait with children of normalized types C_1, ..., C_n:

def ordinal(x: MirroredMonoType) = x match { case _: C_1 => 0 ... case _: C_n => n - 1 }

Here, the normalized type of a class C is C[?, ...., ?] with a wildcard for each type parameter. The normalized type of an object O is O.type.

Attributes

If this is the class backing a serializable singleton enum value with base class MyEnum, and not deriving from java.lang.Enum add the method:

If this is the class backing a serializable singleton enum value with base class MyEnum, and not deriving from java.lang.Enum add the method:

private def readResolve(): AnyRef =
  MyEnum.fromOrdinal(this.ordinal)

unless an implementation already exists, otherwise do nothing.

Attributes

If this is a static object Foo, add the method:

If this is a static object Foo, add the method:

private def writeReplace(): AnyRef =
  new scala.runtime.ModuleSerializationProxy(classOf[Foo.type])

unless an implementation already exists, otherwise do nothing.

All static objects receive the Serializable flag in the back-end, so we do that even for objects that are not serializable at this phase.

Attributes