2010-05-11 3 views
3

Учитывая это:Self-тип рассогласование в Scala

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

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

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

Я пытаюсь определить реализацию следующим образом:

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 
    } 
} 

Который дает мне следующие ошибки:

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 { 
             ^

Я не понимаю, почему. В конце концов, V - это просто псевдоним для SensorView[T], и пути одинаковы, так как это может не соответствовать?

ответ

3

Нашел это: конечно, параметры T в общих типах различны. Поэтому я должен был написать вместо этого

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

    trait SensorView extends View { 
    } 

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

    class SensorPresenter extends Presenter { 
    var view: V 
    } 
} 
Смежные вопросы