-
-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mutation bug: "Can't change the value of self" #64
Comments
@dkubb Yeah, good catch an easy to fix. Will address it soon. Interesting this one wasnt found more early. Most likely the amount of useing the op-assign operators was reduced a lot with dm2-rom-style. |
@dkubb While generalizing this kind of error I think I should also exclude cases with literal lhs! |
@mbj yeah, that's a good idea. Are there notes that represent literal values and includes things like: At first I was thinking you should only include nodes known to support assignment; but then I realized you could easily accidentally miss whole classes of nodes with that approach. I guess using an explicit exclude approach is better. While it might take some tweaking to get the list complete, mutating everything by default is probably a better approach. |
@dkubb Jo, I'd only do blacklisting here. And yes identifying literals is easy just use
|
Also detection of that case is easy. The "inner" nodes mutator, the mutator that mutates the "self.attribute" has to detect it is within an op assign parent. And it will NOT invoke the "emit receiver" mutation if the receiver is of that type list I gave above. I really love mutants design here. We have access to the parent mutator and can easily branch on the parents Mutant is a recursive tree walker emitting mutations and tracking context. |
It would be kind of weird for the receiver to be one of those nodes listed, besides self of course, but I suppose it could happen if you were to do something like: class String
attr_accessor :extra
end
# will blow up when mutated to: '' = 42
''.extra = 42 Even though I would consider this a bit dumb, it is valid ruby. |
@dkubb Do not confuse assignment with op-assign. |
My pref comment is not valid. @dkubb My english limits me here, let the code that fixes the problem speek. Soon, still busy with other stuff. |
@mbj awesome, thanks! I'll test this out now |
@mbj works great. the code that triggered this bug originally works great with mutant now. Thanks! |
I just found a bug in how mutant mutates expressions like:
self.attr ||= something
, eg:The text was updated successfully, but these errors were encountered: