I would like to define a class hierarchy with about 100 case classes deriving from common base. The types are describing nodes in the AST hierarchy, like this one. I would like to do something along the lines of:
trait Base { def doCopy: Base } trait CloneSelf[T <: CloneSelf[T]] extends Base { self: T => def copy(): T override def doCopy: T = copy() } case class CaseA(a: String) extends Base with CloneSelf[CaseA] case class CaseB(b: Int) extends Base with CloneSelf[CaseB] This gives an error, because the existence of my copy prevents the case classes from defining the automatic copy. Is there some way how to implement the "clone" doCopy so that is uses the automatic copy of those case classes?