Compilation runs code outside modules?

I’m still experimenting with elixir and learning, heard about vscode-elixir-ls and started using it. So I was amazed by how it detected such an error that should happen at runtime. It seems actually to have run the code and it’s showing the error that would happen if I did run it. I thought that was Dialyzer but then realized if I ran elixirc on the file it shows the same error. Also, realized that it happens because of the code outside the module, so does it actually run all code outside modules during compilation?

Check out Why does the compilation of modules also execute code?

2 Likes