Self-type mismatch in Scala

Posted by Alexey Romanov on Stack Overflow See other posts from Stack Overflow or by Alexey Romanov
Published on 2010-05-11T13:00:01Z Indexed on 2010/05/11 13:04 UTC
Read the original article Hit count: 327

Filed under:

Given this:

abstract class ViewPresenterPair {
  type V <: View 
  type P <: Presenter

  trait View {self: V =>
    val presenter: P
  }

  trait Presenter {self: P =>
    var view: V
  }
}

I am trying to define an implementation in this way:

case class SensorViewPresenter[T] extends ViewPresenterPair {
  type V = SensorView[T]
  type P = SensorPresenter[T]

  trait SensorView[T] extends View {
  }

  class SensorViewImpl[T](val presenter: P) extends SensorView[T] {
    presenter.view = this
  }

  class SensorPresenter[T] extends Presenter {
    var view: V
  }
}

Which gives me the following errors:

error: illegal inheritance;
 self-type SensorViewPresenter.this.SensorView[T] does not conform to SensorViewPresenter.this.View's selftype SensorViewPresenter.this.V
         trait SensorView[T] extends View {
                                     ^
<console>:13: error: type mismatch;
 found   : SensorViewPresenter.this.SensorViewImpl[T]
 required: SensorViewPresenter.this.V
        presenter.view = this
                         ^
<console>:16: error: illegal inheritance;
 self-type SensorViewPresenter.this.SensorPresenter[T] does not conform to SensorViewPresenter.this.Presenter's selftype SensorViewPresenter.this.P
         class SensorPresenter[T] extends Presenter {
                                          ^

I don't understand why. After all, V is just an alias for SensorView[T], and the paths are the same, so how can it not conform?

© Stack Overflow or respective owner

Related posts about scala