docs/_docs/reference/error-codes/E218.md
This error is emitted when the erased modifier is used with a definition that doesn't support it.
Only non-lazy immutable values (val) can be marked as erased. The erased modifier is not allowed for:
lazy val)var)Additionally, this error can occur when a value's type implicitly makes it erased (by extending compiletime.Erased) but the definition kind doesn't support erasure.
import scala.language.experimental.erasedDefinitions
object Test:
erased lazy val x: Int = 42
-- [E218] Type Error: example.scala:4:18 ---------------------------------------
4 | erased lazy val x: Int = 42
| ^
| `erased` is not allowed for this kind of definition.
|-----------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| Only non-lazy immutable values can be `erased`
-----------------------------------------------------------------------------
Use erased only with non-lazy val definitions:
import scala.language.experimental.erasedDefinitions
object Test:
erased val x: Int = 42
If you need a method with erased parameters, use erased parameters instead:
import scala.language.experimental.erasedDefinitions
def compute(erased hint: Int): Int = 42