Context bound on trait

78 Views Asked by At

I would like to do something akin to

trait Copyable[T] {
  extension (o: T) def copy: T
}

trait A : Copyable { // Context bound is not legal here...
  def foo(): A = copy
}

or

trait A {
  this: (A: Copyable) => // Context bound is not legal here...
  def foo(): A = copy
}

In other words, I would like the trait A to "extend" Copyable, or only be mixable with Copyable types.

Note: Ideally, foo would have type this.static_type (doesn't currently exist), which would represent the most specific static type of this.

0

There are 0 best solutions below