Skip to content

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

Open
jrudolph wants to merge 2 commits into
jorgeortiz85:masterfrom
jrudolph:companion-object-warning
Open

warn if a companion object of a case class is referenced in a stand-alone fashion#5
jrudolph wants to merge 2 commits into
jorgeortiz85:masterfrom
jrudolph:companion-object-warning

Conversation

@jrudolph

Copy link
Copy Markdown
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.

…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.
@jrudolph

Copy link
Copy Markdown
Contributor Author

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

dragos commented Apr 22, 2013

Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants