linter icon indicating copy to clipboard operation
linter copied to clipboard

warn if a companion object of a case class is referenced in a stand-alone fashion

Open jrudolph opened this issue 13 years ago • 2 comments

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.

jrudolph avatar Apr 25 '12 12:04 jrudolph

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.

jrudolph avatar Apr 25 '12 13:04 jrudolph

Why not make this warning actor-specific? I agree there are too many legitimate uses otherwise.

dragos avatar Apr 22 '13 15:04 dragos