-
Notifications
You must be signed in to change notification settings - Fork 12
Description
If you generate a simple Phoenix app with mix phx.new, add Gradient as a dependency, and then run mix gradient, you get these errors (among others). For an example, see this PR: #149
lib/simple_phoenix_app/repo.ex: The spec rollback/1 on line 2 doesn't match the function name/arity
lib/simple_phoenix_app_web/views/layout_view.ex: The spec template_not_found/2 on line 2 doesn't match the function name/arity
lib/simple_phoenix_app_web/views/page_view.ex: The spec template_not_found/2 on line 2 doesn't match the function name/arity
The spec referred to is generated at compile time by a use statement. Using lib/simple_phoenix_app_web/views/layout_view.ex as an example, here's the code in that actual file:
# lib/simple_phoenix_app_web/views/layout_view.ex:1-2
defmodule SimplePhoenixAppWeb.LayoutView do
use SimplePhoenixAppWeb, :view
...
And here's the code that use SimplePhoenixAppWeb, :view generates:
# deps/phoenix_view/lib/phoenix_view.ex:209-223
quote do
...
@spec template_not_found(binary, map) :: no_return
def template_not_found(template, assigns) do
Phoenix.View.__not_found__!(__MODULE__, template, assigns)
end
...
In the quoted code, the spec correctly comes right before the function. But when I decompile the LayoutView module (via Gradient.Debug.print_erlang(SimplePhoenixAppWeb.LayoutView)), the spec is placed at the beginning of the file, before the __info__ function definition. I believe that's why it gives the error.
I think the way to fix this would be to get the Elixir AST separately from the compiled bytecode so we could check if the function is generated, and in that case, allow the specs to be out of order.