title: illegal inheritance; self-type .... does not conform to
body: <p>I am trying to implement a cake pattern like code, but I get:</p>
  
  <pre><code>Error:(47, 36) illegal inheritance;
   self-type app.server.im.Im_Api_Service_Impl.type does not conform to app.server.im.Persistence[app.server.im.State.State]'s selftype app.server.im.Persistence[app.server.im.State.State] with app.server.im.Persistable[app.server.im.State.State]
  object Im_Api_Service_Impl extends Persistence[State.State]
  </code></pre>
  
  <p>with the code below.</p>
  
  <p>What might be the problem ?</p>
  
  <p>I looked at <a href="https://stackoverflow.com/questions/7378901/scala-illegal-inheritance-self-type-y-does-not-conform-to-xs-selftype-self">this</a> SOF question, but it seems to describe a different scenerio (or maybe I am just not seeing the similarity).</p>
  
  <pre><code>import app.shared.IndexChange
  import app.shared.apiAndModel.im.{CanCreateEntity, Im_Api_Interface, LineShared, LineSharedPayload, UUID}
  import upickle.default._
  object State {
    type State = Seq[LineShared]
  }
  
  trait  Im_Api_Service extends Im_Api_Interface with Persistable[State.State] {
    implicit object CanCreate extends CanCreateEntity
    import State.State
    val init = List("egy", "ketto", "harom", "negy", "ot", "hat", "het", "nyolc").map(LineSharedPayload(_)).map(LineShared(_))
  
    val fileNameForPersistence="state"
  
    var state: State = init
  
    def setState(s:State)={state=s}
  
    override def getLines(): Seq[LineShared] = state
  
  
    def moveLine(ls: State, from: Int, to: Int): Seq[LineShared] = {
      val r=IndexChange(from, to).updatedList[LineShared](ls.toList)
      r
    }
  
    override def moveLine(from: Int, to: Int): Seq[LineShared] = {state=moveLine(state, from, to);state;}
  
    override def newLine(pl: LineSharedPayload): Seq[LineShared] = {
      setState(state :+ LineShared(pl))
      state
    }
  
    def getLine(ls:State, id: UUID): Option[LineShared] = ls.find(_.id == id)
  
    override def getLine(id: UUID): Option[LineShared] = getLine(state,id)
  
  
    override def updateLine(l: LineShared): State = {
      setState(state.map(ll =&gt; if (ll~l) l else ll ))
      state
    }
  }
  
  object Im_Api_Service_Impl extends Persistence[State.State]
  
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
                 illegal inheritance problem HERE
  
  
  trait Persistable[State]
  {
    val fileNameForPersistence:String
    var state :State
  
  }
  
  trait Persistence[State] { this:Persistable[State] =&gt;
    def serializeState(s: State): String = write(s)
  
    // TODO add timestamp to filename
    def saveState(): Unit = writeToFile(serializeState(state), fileNameForPersistence)
  
    def loadState(): Unit = {
      try {
        state = deserializeState(readFromFile(fileNameForPersistence))
      }
      catch {
        case e: Exception =&gt; println(e)
      }
    }
  
    def writeToFile(s: String, fn: String): Unit = {
      import java.io._
      val pw = new PrintWriter(new File(fn))
      pw.write(s)
      pw.close
    }
  
  
    def readFromFile(fn: String): String = {
      val source = scala.io.Source.fromFile(fn)
      val lines: String = try source.mkString finally source.close()
      lines
    }
  
    def deserializeState(s: String): State = read[State](s)
  }
  </code></pre>