Skip to content

Remove recursion with method_added #5066

Closed
@bew

Description

@bew

This code used to work (I don't remember the version and I didn't managed to bisect that properly with versions before 0.21.0):

module ModuleName
  macro method_added(meth)
    {% puts "Method #{meth.name} added" %}
    {{meth}}
  end

  # triggers the hook
  def normal_method
  end
end

It used to be called once, display the proper message, and defines the method.
(In fact this is a bad example, see #5066 (comment) for a better one!)

Now I get:

"Method normal_method added"
"Method normal_method added"
"Method normal_method added"
"Method normal_method added"
...

Followed by a stackoverflow error...

This is because the macro is expanded to:

 
def normal_method
end

and during the interpretation of the macro expansion, the macro method_added is called (again) for the generated method.

I think that methods defined by a method_added expansion should not trigger method_added again, but methods defined in other places (normal code or other macros) should trigger it.

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