E236: Bad Erased
This error is emitted when the erased modifier is used in a position where it is not allowed.
When erasedDefinitions is enabled, erased can be used as a modifier of definitions and of function parameters. Inside parentheses, the parser cannot tell right away whether it is reading a parameter list followed by => or an ordinary expression. A binding such as erased y: Int is only legal if the parentheses turn out to form the parameter list of a function literal. If they form a tuple, an argument list or a parenthesized expression, this error is reported.
Example
import scala.language.experimental.erasedDefinitions
val x = (1, erased y: Int)
Error
-- [E236] Syntax Error: example.scala:3:12 -------------------------------------
3 |val x = (1, erased y: Int)
| ^^^^^^^^^^^^^
| erased cannot be used here
|-----------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| erased can be used only as a modifier in definitions or function parameters.
-----------------------------------------------------------------------------
Solution
import scala.language.experimental.erasedDefinitions
// Use `erased` on a parameter of a function literal
val f = (x: Int, erased y: Int) => x
import scala.language.experimental.erasedDefinitions
// Or on a parameter of a method
def g(x: Int, erased y: Int): Int = x
In this article