Skip to content
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

[BUG] Calling super inside decorator executes the function twice #55

Open
dkuku opened this issue Dec 15, 2024 · 0 comments
Open

[BUG] Calling super inside decorator executes the function twice #55

dkuku opened this issue Dec 15, 2024 · 0 comments

Comments

@dkuku
Copy link

dkuku commented Dec 15, 2024

Hey @arjan , I'm not sure if this is elixir super bug or decorator it would be nice if you could confirm

Mix.install([
  {:decorator, "~> 1.4"}
])

defmodule PrintDecorator do
  use Decorator.Define, print: 0

  def print(body, context) do
    quote do
      IO.puts("Function called: " <> Atom.to_string(unquote(context.name)))
      unquote(body)
    end
  end
end

defmodule BehaviourTest do
  @callback test(number(), number()) :: number()
end

defmodule DefaultMod do
  defmacro __using__(_opts) do
    quote do
      @behaviour BehaviourTest

      def test(x, y) do
        IO.puts(DefaultMod)
        x + y
      end

      defoverridable BehaviourTest
    end
  end
end

defmodule DecorModSuper do
  use DefaultMod
  use PrintDecorator

  @decorate print()
  def test(x, y) do
    IO.puts(__MODULE__)
    super(x, y)
  end
end

this ends up with:

# Demonstrate the implementations
DecorModSuper.test(1, 2)

Function called: test
Elixir.DecorModSuper
Elixir.DecorModSuper
Elixir.DefaultMod
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

No branches or pull requests

1 participant