Reduce min arg in parallel assignment. Fixes #147
Created by: madgen
When parallel assignment is used together with write syntactic sugar, ie. method names ending with '=' followed by an argument, the parser generates a masgn node which contain the send nodes with one less argument than expected. Those arguments are gathered as an array in the second child of masgn node.
Examples:
h = Hash.new
h[1], h[2] = 1, 2
# s(:masgn,
# s(:mlhs,
# s(:send,
# s(:send, nil, :h), :[]=,
# s(:int, 1)), # Here normally we would have an extra argument.
# s(:send,
# s(:send, nil, :h), :[]=,
# s(:int, 2))), # Here normally we would have an extra argument.
# s(:array,
# s(:int, 3),
# s(:int, 4)))
# Same problem occurs in
class Hey
def x=(_); end
end
h = Hey.new
h.x, h.x = 1, 2
This commit fixes that by reducing the required argument size by one on such sugared method names.
It also reduces the sensitivity of the analysis in the case of a single writer method usage, but that would be a syntax error anyway.
A better fix would involve having access to the parent node, so we can check if it is a parallel assignment, or starting the analysis on a higher up node.