Skip to content

Use of include with anonymous module with method breaks further parsing #627

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

Closed
jeremyevans opened this issue Jun 1, 2018 · 2 comments · Fixed by #637
Closed

Use of include with anonymous module with method breaks further parsing #627

jeremyevans opened this issue Jun 1, 2018 · 2 comments · Fixed by #637

Comments

@jeremyevans
Copy link
Contributor

This issue occurs when you have a include or extend method call inside a class/module, and an argument inside include or extend that uses a block, and define a method with parentheses inside the block. In such cases, future classes (A::C and A::D in the examples below) are missed by the parser.

Example failing code:

module A
  class B
    include(Module.new do
      def e(m)
      end
    end)
  end

  class C
  end

  class D
  end
end

Removing the parentheses when defining the method is sufficient to work around this bug:

module A
  class B
    include(Module.new do
      def e m 
      end
    end)
  end

  class C
  end

  class D
  end
end

As is using a local variable for the Module.new result and passing that to include:

module A
  class B
    m = Module.new do
      def e(m)
      end
    end
    include m
  end

  class C
  end

  class D
  end
end

Here's another failing case showing the problem is not related to Module.new or do/end vs {/}:

module A
  class B
    extend(e {
      def f(g)
      end
    })
  end

  class C
  end

  class D
  end
end
@jeremyevans
Copy link
Contributor Author

Note that when using {/} instead of do/end, instead of not picking up the classes, the parser picks up A::C as C and A::D as D.

@aycabta
Copy link
Member

aycabta commented Jul 11, 2018

@jeremyevans Thank you for your reporting!

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 a pull request may close this issue.

2 participants