linter
linter copied to clipboard
warn if a companion object of a case class is referenced in a stand-alone fashion
This happens easily when writing actor based code where you often have a set of messages defined like this:
case class Start(arg: Int) case object Stop
If you now use Start without the argument in pattern matches (like in receive) or
message sends (self ! Start) your code may fail silently because you are sending the
companion object around which is rarely what you want to do.
Applying this to my own projects, this has still too many false positives. The problem is that there often is a valid use of companion objects i.e. as the constructor for the case class. Do you have an idea how you could check if the tree in question is in a parameter position of an Apply where a value of type FunctionX is expected? I think this could discriminate it but I can't really think of an easy way to do this match.
Why not make this warning actor-specific? I agree there are too many legitimate uses otherwise.