trait T[X <: T[X]] { self: X =>
  def m(other: X): X
}

class Foo extends T[Foo] {
  override def merge(other: Foo): Foo = this
}