Skip to content

Commit

Permalink
Fix forward arg mutations
Browse files Browse the repository at this point in the history
[Fix #1316]

* Do not emit naked forward arg argument promotion
* Do not mutate away forard args, this would syntactically
  invalidate the generated source.
  • Loading branch information
mbj committed Apr 10, 2022
1 parent 20ab333 commit 7c6aee9
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 9 deletions.
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v0.11.6 2022-04-10

* [#1317](https://github.com/mbj/mutant/pull/1317)

Fix forward arg mutations.

# v0.11.5 2022-04-03

* [#1314](https://github.com/mbj/mutant/pull/1314)
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
mutant (0.11.5)
mutant (0.11.6)
diff-lcs (~> 1.3)
parser (~> 3.1.0)
regexp_parser (~> 2.0, >= 2.0.3)
Expand Down
22 changes: 16 additions & 6 deletions lib/mutant/mutator/node/arguments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,27 @@ def dispatch
end

def emit_argument_presence
emit_type unless removed_block_arg?(EMPTY_ARRAY)
emit_type unless removed_block_arg?(EMPTY_ARRAY) || forward_arg?

Util::Array::Presence.call(children).each do |children|
unless removed_block_arg?(children) || (children.one? && n_mlhs?(children.first))
emit_type(*children)
children.each_with_index do |removed, index|
new_arguments = children.dup
new_arguments.delete_at(index)
unless n_forward_arg?(removed) || removed_block_arg?(new_arguments) || only_mlhs?(new_arguments)
emit_type(*new_arguments)
end
end
end

def removed_block_arg?(children)
anonymous_block_arg? && children.none?(&ANONYMOUS_BLOCKARG_PRED)
def only_mlhs?(new_arguments)
new_arguments.one? && n_mlhs?(new_arguments.first)
end

def forward_arg?
children.last && n_forward_arg?(children.last)
end

def removed_block_arg?(new_arguments)
anonymous_block_arg? && new_arguments.none?(&ANONYMOUS_BLOCKARG_PRED)
end

def anonymous_block_arg?
Expand Down
4 changes: 3 additions & 1 deletion lib/mutant/mutator/node/send.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ def emit_argument_propagation

argument = Mutant::Util.one(arguments)

emit_propagation(argument) unless n_kwargs?(argument)
return if n_kwargs?(argument) || n_forwarded_args?(argument)

emit_propagation(argument)
end

def mutate_receiver
Expand Down
2 changes: 1 addition & 1 deletion lib/mutant/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

module Mutant
# Current mutant version
VERSION = '0.11.5'
VERSION = '0.11.6'
end # Mutant
26 changes: 26 additions & 0 deletions meta/def.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,29 @@
mutation 'def self.foo(a, b); raise; end'
mutation 'def self.foo(a, b); super; end'
end

Mutant::Meta::Example.add :def do
source 'def foo(...); end'

mutation 'def foo(...); raise; end'
mutation 'def foo(...); super; end'
end

Mutant::Meta::Example.add :def do
source 'def foo(a, ...); end'

mutation 'def foo(_a, ...); end'
mutation 'def foo(a, ...); raise; end'
mutation 'def foo(a, ...); super; end'
mutation 'def foo(...); end'
end

Mutant::Meta::Example.add :def, :send do
source 'def foo(...); bar(...) end'

mutation 'def foo(...); bar; end'
mutation 'def foo(...); raise; end'
mutation 'def foo(...); super; end'
mutation 'def foo(...); nil; end'
mutation 'def foo(...); end'
end

0 comments on commit 7c6aee9

Please sign in to comment.