score:2
Since you declare Disconnect
to be a case class
, the compiler automatically generates a companion object Disconnect
, which holds all the neat apply
and unapply
methods. Therefore, Peer.Disconnect
is a perfectly valid expression of the singleton type Peer.Disconnect.type
. One might argue that it wouldn't have happened if you used Akka Typed right from the beginning, but in your code, the !
method accepts anything, so in order to force the compiler to emit some meaningful error messages, you need something else. Here is one simple approach:
- Revert to the state where
Disconnect
was a singleton object, without an associated case class. - Remove the
Disconnect
definition altogether. Addcase class NewDisconnect
instead. Now every occurrence ofPeer.Disconnect
will become a proper error. - Replace all
Peer.Disconnect
byPeer.NewDisconnect(foo)
- Rename
NewDisconnect
toDisconnect
.
score:1
The problem is not in the compiler but in the method !
which accepts Any
as argument:
def !(message: Any)(implicit sender: ActorRef = Actor.noSender): Unit
so we could change the argument to anything and it would still compile, for example,
revocationTimeout.peer ! "woohoo" // compiles OK!
On the other hand if we look at the corresponding Akka Typed !
method
implicit final class ActorRefOps[-T](val ref: ActorRef[T]) extends AnyVal {
def !(msg: T): Unit = ref.tell(msg)
}
then we see it is parameterised with type parameter T
and the compiler would catch it.
score:1
I assume that !
is the tell operator from akka actors.
It's signature is
def !(message: Any)(implicit sender: ActorRef = Actor.noSender): Unit
So you can send to it literally anything, in this case you are sending the type Disconnect. This is one of the greatest disadvantages from using akka actors, that's why there is a new module akka typed where you define a type-safe behavior for your actors.
You may wonder why this doesn't blow up in runtime if you are sending an object that you don't expect. The reason is that actor's receive is a PartialFunction[Any, Unit] that "discards" the messages that are not defined for the PF.
Source: stackoverflow.com
Related Query
- How to make the scala compiler find case classes used with wrong arguments
- How can I get random data generated for scala case classes with the ability to "change some values" for unit testing?
- How to convert between to case classes with `mostly the same` fields using Scala Shapeless
- How do I find the correct Maven archetype project for developing with Scala in Eclipse?
- Scala spark: how to use dataset for a case class with the schema has snake_case?
- Scala Case Classes vs. Protocol Buffers with Akka over the network
- How do I pull apart Case Classes filled with Options in Scala
- How to interact with the compiler in Scala code itself?
- How to make compiler check that 2 method arguments have the same type?
- How can I find the statements in a Scala program from within a compiler plugin?
- unapply method of a case class is not used by the Scala compiler to do pattern matching, why is that?
- Pattern Matching chooses the wrong case if used with ClassTag
- Why in this scala snippet the compiler loses the type [P] of the payload? How can I make this snippet compile?
- How do I make a Java friendly API for case classes with optional fields
- How to make aliases for the classes in scala
- How do I get the type signature to agree with the scala compiler when extracting a value out of an Option[A]?
- Scala - how to make the SortedSet with custom ordering hold multiple different objects that have the same value by which we sort?
- Handling heavy load on the GC with Scala Case Classes
- How to make Scala Presentation Compiler happy with Binding.scala?
- How to use Avro serialization for scala case classes with Flink 1.7?
- How to handle with null values in Scala case classes in Flink?
- How does the Scala compiler synthesize implicit evidence with `<:<`?
- Several case classes with the same behavior in Scala
- How to define case class with a list of tuples and access the tuples in scala
- How to parse a csv with matching case class and store the output to treemap[Int, List[List[InputConfig]] object in scala
- Filter list of scala case classes by list with the class?
- Why does the Scala compiler disallow overloaded methods with default arguments?
- How to update a mongo record using Rogue with MongoCaseClassField when case class contains a scala Enumeration
- Scala - how to print case classes like (pretty printed) tree
- How to get around the Scala case class limit of 22 fields?
More Query from same tag
- How can i make an immutable subclass of a superclass with final setter methods?
- sbt console - tab completion
- Play JSON - How to generify this in Scala for Json handling?
- scala Option[Int] primitive Boxing and Unboxing
- Overloaded Method Syntax in Scala
- Storing relational data in Apache Flink as State and querying by a property
- Who can explain the meaning of this scala code
- Scala web framework performance on raspberry pi
- scala: Adding attributes (odd and even rows) to xml table
- How to instantiate an Akka actor from a type parameter
- How to convert a list to a list of tuples in scala?
- What is the meaning of an assumption in scala compared to an assertion?
- Scala and interfaces
- Constraint a scala type such that I would never need to check for null?
- Scala Slick: Getting number of fields with a specific value in a group by query
- What is the most elegant way to deal with an external library with internal state using a function programming language?
- Unable to use java code in scala
- Redirect HTTP requests to HTTPS on Google App Engine and Play Framework
- List of Lists to HashMap[Index of List] -> List - Scala
- Spark SQL - replace nulls with default values
- Scala: Most efficent collection for simple iteration
- How to return multiple JSON objects using Spark SQL in Scala
- How to pass bash variable as a string not array to a scala file
- Scala: convert map to case class
- Spark/Scala group similar words and count
- How to use JCache in Scala? I get compiler type error: found String required K
- sbt run error: java.lang.RuntimeException: Nonzero exit code: 1
- call method overrided in scala
- Is it possible to auto infer result types in Slick?
- Scala/scoverage: Is it necessary to make a clean rebuild for releasing a jar for publishing?