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: alias lifting produces broken code when aliases conflict with other existing usages #193

Open
jsw800 opened this issue Sep 4, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@jsw800
Copy link

jsw800 commented Sep 4, 2024

Versions

  • Elixir: 1.17.1
  • Styler: 1.0.0

Example Input

Before running mix format:

defmodule SomeModule do
  def do_something(token) do
    # Guardian.Token.Jwt is a library module in the guardian library
    # MyApp.Guardian is a module defined inside my application
    Guardian.Token.Jwt.decode_token(MyApp.Guardian, token)
  end

  def do_something_else do
    Application.get_env(:my_app, MyApp.Guardian)
  end
end

Stacktrace / Current Behaviour

After running mix format:

defmodule SomeModule do
  alias MyApp.Guardian

  def do_something(token) do
    # elixir now can't find the Guardian.Token.Jwt module because it is
    # looking for MyApp.Guardian.Token.Jwt which is not a real module
    Guardian.Token.Jwt.decode_token(Guardian, token)
  end

  def do_something_else do
    Application.get_env(:my_app, Guardian)
  end
end
@jsw800 jsw800 changed the title Alias lifting produces broken code when aliases conflict with other existing usages bug: alias lifting produces broken code when aliases conflict with other existing usages Sep 4, 2024
@novaugust
Copy link
Contributor

thanks for the report! definitely something styler's supposed to notice, sorry that it's got a bug there

@novaugust
Copy link
Contributor

hey @jsw800 , i wasn't able to reproduce the issue with the snippet you gave me:

https://github.com/adobe/elixir-styler/compare/me/fix-193?expand=1

tests still pass. is there more context you can provide?

@jsw800
Copy link
Author

jsw800 commented Sep 4, 2024

Ah sorry about that - I had kinda changed it from my original code so as to not share my actual source code. It looks like the difference between my original code and the example I shared is that MyApp.Guardian was actually MyApp.Something.Guardian. When the code looks like this, the test fails as expected:

defmodule SomeModule do
  @moduledoc false

  def do_something(token) do
    # Guardian.Token.Jwt is a library module in the guardian library
    # MyApp.Something.Guardian is a module defined inside my application
    Guardian.Token.Jwt.decode_token(MyApp.Something.Guardian, token)
  end

  def do_something_else do
    Application.get_env(:my_app, MyApp.Something.Guardian)
  end
end

@novaugust
Copy link
Contributor

ty, got it now :)

@novaugust novaugust added the bug Something isn't working label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants