elixir-lang / elixir

Elixir is a dynamic, functional language for building scalable and maintainable applications
https://elixir-lang.org/
Apache License 2.0
24.51k stars 3.38k forks source link

Wrong file+line when module attribute aliases are expanded #13819

Closed josevalim closed 1 month ago

josevalim commented 2 months ago
alias My.Schema.User
alias My.Schema.Account
@module_map %{
  account: Account,
  user: User,
  ...
}

IIRC correctly these do not generate compile time dependencies if the attributes are used inside a function only. Run mix trace to double check though.

Wow, I double-checked because I also thought these generated compile-time dependencies, and of course you are correct, very nice. The output that mix trace gives is a bit surprising, it lists at the end of a file with "nofile:" as the source, e.g., when line 28 uses the @example to call a function of a module

Compiling 1 file (.ex)
lib/my_file.ex:5: require MyApp.Something... (export)
lib/my_file.ex:5: call MyApp.Something.../1 (compile)
lib/my_file.ex:11: alias MyApp.Something... (runtime)
lib/my_file.ex:27: alias MyApp.Something... (runtime)
lib/my_file.ex:48: alias MyApp.Something... (runtime)
...
lib/my_file.ex:282: call MyApp.Something.../2 (runtime)
lib/my_file.ex:283: call MyApp.Something.../2 (runtime)
nofile:27: alias MyApp.Something... (compile)

Originally commented at https://github.com/elixir-lang/elixir/issues/13762#issuecomment-2341189737

josevalim commented 1 month ago

Closed in 4104bfc1936aad3ac0848a6204b3d77dcf02f56f, I used the wrong reference.

Unfortunately we don't have the file information at that point, but I made it point to @attrname:LINE:, where the line is where it is accessed (not where it is defined).