arjan / decorator

Function decorators for Elixir
MIT License
386 stars 21 forks source link

Decorator is not compatible with `@impl` directive introduced in Elixir 1.5 #13

Closed samsondav closed 5 years ago

samsondav commented 7 years ago

Elixir 1.5 introduces the @impl true directive to declare functions as callback implementations of a behaviour.

These declarations don't work with the @decorate macro. Example:

defmodule MyModule
  @behaviour MyBehaviour
  @behaviour AnotherBehaviour

  @impl MyBehaviour
  @decorate my_callback() # <== causes the @impl to emit a warning
  def my_callback do
  end

  @impl AnotherBehaviour
  def another_callback do
  end
end
whitfin commented 6 years ago

@samphilipd does that still happen if you put the @decorate above the @impl?

samsondav commented 6 years ago

Yes. Have tried both ways around.

arjan commented 6 years ago

Can you provide a full testcase? Tried it with the following but it does not cause warnings:

defmodule DecoratorImplTest.Fixture.MyDecorator do
  use Decorator.Define, some_decorator: 0

  def some_decorator(body, _context) do
    body
  end
end

defmodule DecoratorImplTest.Fixture.MyModule do
  use DecoratorImplTest.Fixture.MyDecorator
  use GenServer

  @impl true
  @decorate some_decorator()
  def init(value) do
    {:ok, value}
  end

  @impl true
  @decorate some_decorator()
  def handle_call(_, _, _) do
    {:noreply, 1, 1}
  end
end

defmodule DecoratorImplTest.Basic do
  use ExUnit.Case
  alias DecoratorImplTest.Fixture.MyModule

  test "impl decoration" do
    assert {:ok, 1} = MyModule.init(1)
  end
end
arjan commented 5 years ago

Please reopen if this is still relevant.