E077: Value Class Parameter May Not Be A Var
This error is emitted when a value class (a class extending AnyVal) has its parameter declared as var instead of val.
A value class must have exactly one val parameter. Using var would imply mutability, which is incompatible with how value classes are represented at runtime.
Example
class Wrapper(var value: Int) extends AnyVal
Error
-- [E077] Syntax Error: example.scala:1:18 -------------------------------------
1 |class Wrapper(var value: Int) extends AnyVal
| ^
| A value class parameter may not be a var
|-----------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| A value class must have exactly one val parameter.
-----------------------------------------------------------------------------
Solution
// Use val instead of var
class Wrapper(val value: Int) extends AnyVal
// If you need mutability, use a regular class
class Wrapper(var value: Int)
In this article