E034: Existential Types No Longer Supported
This error is emitted when existential types syntax (using forSome) is used. Existential types are no longer supported in Scala 3.
Existential types were a feature in Scala 2 that allowed abstracting over unknown types using the forSome syntax. In Scala 3, this feature has been removed in favor of simpler and more principled alternatives.
Instead of existential types, you should use:
- Wildcard types: Use
?(or_in Scala 2 compatibility mode) for unknown type parameters - Type parameters: Use generic methods or classes with explicit type parameters
- Dependent types: For more advanced use cases
Example
def example[T]: List[T forSome { type T }] = List()
Error
-- [E034] Syntax Error: example.scala:1:23 -------------------------------------
1 |def example[T]: List[T forSome { type T }] = List()
| ^^^^^^^
| Existential types are no longer supported -
| use a wildcard or dependent type instead
|-----------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| The use of existential types is no longer supported.
|
| You should use a wildcard or dependent type instead.
|
| For example:
|
| Instead of using forSome to specify a type variable
|
| List[T forSome { type T }]
|
| Try using a wildcard type variable
|
| List[?]
-----------------------------------------------------------------------------
Solution
// Use a wildcard type
def example: List[?] = List()
// Alternative: use a type parameter
def example[T]: List[T] = List()
// Alternative: use Any if the type doesn't matter
def example: List[Any] = List()
In this article