A solution is to declare that your trait must be applied to a class with a copy method:
trait K[T <: K[T]] {this: {def copy(x: String, y: String): T} =>
val x: String
val y: String
def m: T = copy(x = "hello", y)
}
(unfortunately you can not use implicit parameter in the copy method, as implicit declaration is not allowed in the type declaration)
Then your declaration is ok:
case class L(val x: String, val y: String) extends K[L]
(tested in REPL scala 2.8.1)
The reason why your attempt does not work is explained in the solution proposed by other users: your copy
declaration block the generation of the "case copy
" method.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…