Skip to content

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

Closed
@jeremyevans

Description

@jeremyevans

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions