E212: Only Fully Dependent Applied Constructor Type
This warning is emitted when using an applied constructor type (a type that includes constructor arguments) with a class where not all parameters in the first parameter list are marked as tracked.
Applied constructor types are an experimental feature that allows you to express more precise types by including constructor arguments in the type itself. However, this feature only works correctly when all parameters in the first parameter list are tracked, meaning their values are part of the type.
Example
import scala.language.experimental.modularity
class MyBox(val value: Int)
def example =
val box: MyBox(42) = MyBox(42)
box
Error
-- [E212] Type Warning: example.scala:6:11 -------------------------------------
6 | val box: MyBox(42) = MyBox(42)
| ^^^^^^^^^
|Applied constructor type can only be used with classes where all parameters in the first parameter list are tracked
Solution
Mark the class parameter as tracked to enable applied constructor types:
import scala.language.experimental.modularity
class MyBox(tracked val value: Int)
def example =
val box: MyBox(42) = MyBox(42)
box
Alternatively, remove the applied constructor type syntax if you don't need the precise type tracking:
import scala.language.experimental.modularity
class MyBox(val value: Int)
def example =
val box: MyBox = MyBox(42)
box
In this article