jruby / jruby-parser

JRuby's parser customized for IDE usage

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parser duplicating nodes

camertron opened this issue · comments

Iterating through the nodes of a jruby-parser AST will occasionally yield identical nodes twice. I'm trying to parse this file and identify function calls:

require 'jruby-parser'

root = JRubyParser.parse(contents_of_relations_controller)
function_calls = root.select { |node| node.nodeType.to_s == "FCALLNODE" }
function_calls.size # => 35
function_calls.uniq(&:object_id).size # => 33

Why would the array of function calls contain the same object twice?

Off hand I cannot think of why this would be (we do have a potential duplication of argsnodes with &block I think?), but best route would be to keep reducing the problem code in question until you minimize what could be causing it.

Alright, thanks @enebo. I'll see if I can work up a minimal reproducible case.

It looks like if I remove the _() calls, the problem doesn't happen. Any idea why calling _() results in duplicated nodes?

If your source is only '_()' does it happen? It doesn't seem likely to me. Feels like it must be a combination with something else.

You're absolutely right. After a bit more digging, I discovered it has something to do with array assignment, i.e. []=. This example returns no duplicate objects:

flash.bar = _("I'm a little teapot")

While this returns one duplicate object:

flash[:notice] = _("I'm a little teapot")