hrzndhrn / recode

A linter with autocorrection and a refactoring tool.
MIT License
281 stars 15 forks source link

Execution of Task.AliasOrder failed on file with quoted alias within macro #54

Closed gerbal closed 1 year ago

gerbal commented 1 year ago

I'm getting the error Execution of the Recode.Task.AliasOrder task failed. when defining alias from quoted macro inputs. For example


defmodule RepoTestCase do
  defmacro __using__(opts) do
    repo = Keyword.fetch!(opts, :repo)

    quote do
      alias unquote(repo), as: Repo
    end
  end
end
NickNeck commented 1 year ago

Thanks for reporting this.

NickNeck commented 1 year ago

I can not reproduce it. I will take another look later. Which recode version your are using? I have made a new release some hours ago.

gerbal commented 1 year ago

The issue is present for me in v0.4.4. The issue is persistent in the original code base, but I am unable to recreate it in a simple test case.

Here is the actual exception and stack trace being raised within Recode

12:45:18.593 [error] ** (FunctionClauseError) no function clause matching in Recode.AST.alias_info/1
    lib/recode/ast.ex:446: Recode.AST.alias_info({:alias, [trailing_comments: [], leading_comments: [], end_of_expression: [newlines: 2, line: 17, column: 36], line: 17, column: 7], [{:unquote, [trailing_comments: [], leading_comments: [], closing: [line: 17, column: 25], line: 17, column: 13], [{:repo, [trailing_comments: [], leading_comments: [], line: 17, column: 21], nil}]}, [{{:__block__, [trailing_comments: [], leading_comments: [], format: :keyword, line: 17, column: 28], [:as]}, {:__aliases__, [trailing_comments: [], leading_comments: [], last: [line: 17, column: 32], line: 17, column: 32], [:Repo]}}]]})
    lib/recode/task/alias_order.ex:192: Recode.Task.AliasOrder.sort/2
    (stdlib 4.0.1) lists.erl:1022: :lists.sort/2
    lib/recode/task/alias_order.ex:161: Recode.Task.AliasOrder.update/2
    lib/recode/task/alias_order.ex:144: Recode.Task.AliasOrder.alias_order/2
    lib/sourceror/zipper.ex:420: Sourceror.Zipper.do_traverse_while/3
    lib/recode/task/alias_order.ex:37: Recode.Task.AliasOrder.do_run/2
    lib/recode/runner/impl.ex:70: Recode.Runner.Impl.run_task/5
NickNeck commented 1 year ago

There is a fix in the main branch. If you like you can give it a try.