I understand what the warning "The outer reference in this type test cannot be checked at run time" means (final case class is missing its "outer" pointer if it is not used in the class itself). Still, I find this warning extremely annoying, as it is displayed even when I am not even matching against the type, like in the code below:
object X {
class B {
final case class A(a: Int)
}
def main(arg: Array[String]) = {
}
}
How can I disable this warning, other than making the case class
not final
? Using @unchecked
before the case class
definition does not help.
Perhaps as a workaround we could make case class in effect final by making the constructor private
class B {
case class X private (s: String)
}
which prevents inheritance
class C extends X("") // Error
whilst still allowing construction due to public apply
in the companion
(new B).X("") // OK
The bug does not seem to be present in dotty so once Scala 3 is released it should be possible to revert to final case class (with perhaps regex replacement).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With