trait EventSource { def sendEvent[T](event: T): Unit def eventSourceReceive: Actor.Receive } trait ProductionEventSource extends EventSource { this: Actor => // Original contents of EventSource here }
class Altimeter extends Actor with ActorLogging { this: EventSource => // Original contents of Altimeter here } object Altimeter { // Content as before. We're changing the factory method. def apply() = new Altimeter with ProductionEventSource }
I get this error: [error] classes/eclipse/akkaC/src/main/scala/Altimeter.scala:12: illegal inheritance; [error] self-type zzz.akka.avionics.Altimeter with zzz.akka.avionics.ProductionEventSource does not conform to Altimeter's selftype zzz.akka.avionics.Altimeter with zzz.akka.avionics.EventSource [error] def apply() = new Altimeter with ProductionEventSource
This is fixed if I use the original class Altimeter extends Actor with ActorLogging with ProductionEventSource{ instead of class Altimeter extends Actor with ActorLogging { this: EventSource =>