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

Open
wants to merge 2 commits into
from

Projects

None yet

2 participants

Contributor

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 added some commits Apr 25, 2012
@jrudolph jrudolph warn if a companion object of a case class is referenced in a stand-a…
…lone 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.
7de0056
@jrudolph jrudolph fix stupid syntax error c77dae6
Contributor

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.

dragos commented Apr 22, 2013

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment