-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
Description
3.7.0
I had a code that uses enum and class tags which compiles and looks fine but works incorrect due to specifics of encoding for simple case.
It took me some time to realize that simple enum case isn't equal to sealed trait + case object
encoding and it doesn't actually creates a type.
Example that puzzled me:
enum Token:
case Dot
case Space
case Word(v: String)
def read[T <: Token](t: Token)(using ct: ClassTag[T]): T =
t match
case t: T => t
case _ => throw new Exception(s"$t is not an instance of $ct")
read[Token.Dot.type](Token.Space) // <- no error - while I was expecting to get it
read[Token.Word](Token.Space) // <- throws error - ok
The ambiguity in this example:
ClassTag[Token.Word]
- isToken.Word
everything is fineClassTag[Token.Dot.type]
- isToken
, there is notToken.Dot
type
Expectation
For each enum case there is a proper type and they are diffrerent from each other.
The questions is if it's possible to switch this encoding now or it's too late?