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

Crash when styling module with dynamically generated functions #39

Closed
michallepicki opened this issue May 16, 2023 · 2 comments · Fixed by #40
Closed

Crash when styling module with dynamically generated functions #39

michallepicki opened this issue May 16, 2023 · 2 comments · Fixed by #40

Comments

@michallepicki
Copy link

Elixir / OTP Version

$ elixir --version
Erlang/OTP 25 [erts-13.1.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]

Elixir 1.14.1 (compiled with Erlang/OTP 25)

Example Input

defmodule Example do
  ~w(hello hi)a
  |> Enum.map(fn key ->
    def unquote(key)() do
      :world
    end
  end)
end

Current behaviour / Stacktrace

$ mix style
mix style failed for file: lib/example.ex
** (Styler.StyleError) Error running style Defs on
   Please consider opening an issue at: https://github.com/adobe/elixir-styler/issues/new
** (ArithmeticError) bad argument in arithmetic expression

    :erlang.-(nil, 4)
    lib/style/defs.ex:86: Styler.Style.Defs.run/2
    lib/zipper.ex:345: Styler.Zipper.do_traverse_while/3
    lib/styler.ex:36: anonymous fn/4 in Styler.style/3
    (elixir 1.14.1) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
    lib/styler.ex:34: Styler.style/3
    lib/styler.ex:64: Styler.format/3
    lib/mix/tasks/style.ex:99: Mix.Tasks.Style.style_file/3

Expected Output

no crash

@novaugust
Copy link
Contributor

Thanks for the issue! This is actually the result of an interplay between the pipes style rewriting the single pipe but getting overeager and destroying some metadata needed by the defs-onelining style. Will have a fix out shortly =)

@novaugust
Copy link
Contributor

v0.7.6 released with a fix. thanks again =)

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

Successfully merging a pull request may close this issue.

2 participants