In scala, why type alias in a class cannot be referred for inheritance?

406 views Asked by At

I have the following classes defined:

file: PyRef.scala:

package mypackage
class PyBinding() {
...
}

trait PyRef {

  type Binding = PyBinding
}

file: Link.scala:

class Link() extends PyRef {

  override type Binding = Link.PyBindingImpl
}

object Link {
  class PyBindingImpl() extends PyRef#Binding() {
  }
}

In compilation, the following error was thrown:

Error:(222, 34) class type required but mypackage.PyBinding found
                 ) extends PyRef#Binding() {

Why this happens and what should I do to circumvent it? I'm using Scala 2.10.

1

There are 1 answers

0
0__ On

I don't think you can use type projections A#B in Scala as instantiatable class types. The following two things work

trait Link {
  class PyBindingImpl() extends PyBinding()
}

trait Link {
  val ref: PyRef

  class PyBindingImpl() extends ref.Binding()
}