Closed
Description
I tried adding the new unused flag (from #16157) to my work codebase and was surprised it hit places where private constructors were used to prevent creation of invalid case classes.
Compiler version
With nightly: 3.3.0-RC1-bin-20230112-be10bc6-NIGHTLY
Minimized code
//> using scala "3.3.0-RC1-bin-20230112-be10bc6-NIGHTLY"
//> using option "-Wunused:all"
case class PositiveNumber private (i: Int)
object PositiveNumber:
def make(i: Int): Option[PositiveNumber] =
Option.when(i >= 0)(PositiveNumber(i))
PositiveNumber.make(1).foreach(n => println(n.i))
Output
[warn] ./unused-private-constructor.sc:4:1: unused private member
[warn] case class PositiveNumber private (i: Int)
[warn] ^
[warn] ./unused-private-constructor.sc:4:26: unused private member
[warn] case class PositiveNumber private (i: Int)
[warn] ^^^^
[warn] ./unused-private-constructor.sc:4:42: unused private member
[warn] case class PositiveNumber private (i: Int)
[warn] ^
Expectation
I would expect that the autogenerated private methods of a case class were not warned about since I have no way of removing that warning as an end user.