E148: Typed Case Does Not Explicitly Extend Typed Enum
This error occurs when both an enum class and an enum case have type parameters, but the enum case does not include an explicit extends clause.
When both the enum and its case have type parameters, the compiler cannot automatically infer how the case's type parameters relate to the enum's type parameters. An explicit extends clause is required to specify this relationship.
Example
enum Container[T] {
case Item[U](value: U)
}
Error
-- [E148] Syntax Error: example.scala:2:2 --------------------------------------
2 | case Item[U](value: U)
| ^
|explicit extends clause needed because both enum case and enum class have type parameters
|-----------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| Enumerations where the enum class as well as the enum case have type parameters need
| an explicit extends.
| for example:
| enum Container[T] {
| case Item[U](u: U) extends Container[U]
| }
-----------------------------------------------------------------------------
Solution
enum Container[T] {
// Add explicit extends clause to show how type parameters relate
case Item[U](value: U) extends Container[U]
}
// Alternative: If the case doesn't need its own type parameters,
// use the enum's type parameter directly
enum Container[T] {
case Item(value: T)
}
In this article