Pattern matching with named fields

I support this initiative of named pattern match, hopefully it will be part of Scala 3.1.

I had slightly different idea for similar issues (mostly to avoid refactoring errors mentioned before). With a marker trait on the case class, we can have scalafix warnings when the name of the pattern does not match the name in the case class.
This can be useful when we have same-type arguments and a bit less verbose (no need to repeat the name twice) than the named fields pattern match. Here is a simple example (the project at the moment only contains this scalafix rule).
(Of course the warning can be suppressed.)

1 Like