-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
False positive alias warning on main #13563
Comments
@sabiwara I am not sure if there is a trivial fix for this one. Perhaps we could track the scope of the alias in such cases (for example, only consider it overridden if outside of a function?). |
@josevalim seems to be working #13564. |
I think there may be another problem with aliases outside of functions, e.g. in ExUnit tests, but please correct me if this is correct (it does not warn on 1.16): ExUnit.start()
defmodule MyApp.Data do
defmodule Item do
defstruct id: nil
end
defmodule OtherItem do
defstruct id: nil
end
def list_items do
[%Item{id: 1}]
end
def list_other_items do
[%OtherItem{id: 1}]
end
end
defmodule MyApp.DataTest do
use ExUnit.Case
alias MyApp.Data
alias MyApp.Data.Item
describe "Item" do
test "list_item/0 returns all Items" do
assert [%Item{id: 1}] = Data.list_items()
end
end
describe "OtherItem" do
alias MyApp.Data
alias MyApp.Data.OtherItem
test "list_other_item/0 returns all OtherItems" do
assert [%OtherItem{id: 1}] = Data.list_other_items()
end
end
end
The |
Another example that fails: defmodule MyApp.Data do
def foo do
:ok
end
end
defmodule MyAppWeb.FormComponent do
alias MyApp.Data
defmodule OtherComponent do
@moduledoc false
alias MyApp.Data
def fun do
Data.foo()
end
end
def render do
Data.foo()
OtherComponent.fun()
end
end
MyAppWeb.FormComponent.render() |
Even a simpler case: defmodule Sample do
alias Foo.Baz
def foo, do: Baz
alias Bar.Baz
def bar, do: Baz
end Will revert, and see if we can detect shadowing a different way somehow. |
Elixir and Erlang/OTP versions
Elixir main, any OTP.
Operating system
macOS
Current behavior
This is emitting a unused alias warning, but the warning is used:
Expected behavior
No warnings. :)
The text was updated successfully, but these errors were encountered: