Could Dialyzer process Elixir scripts?

When I run mix dialyzer, only the *.ex files are analyzed. In particular, Elixir scripts (e.g., mix.exs) are not processed. I wonder if this is something that could be worked around.

For example, could the scripts be compiled (in whatever hacky manner) and then handed to Dialyzer for analysis? If not, I’d like to understand the fundamental limitation(s) that prevent this from being done.

-r

1 Like

Nothing in the default toolchain would compile an exs file to disk, but only in memory.

The following is only a theoretical explanation of what has to be done, it neither has been tested by me, nor would I use it in any way (well, perhaps it might be interesting for tests?):

You could invoke the elixir compiler manually to make it compile the exs into beam files. You need to remember though, that this will only ever work for files that create a module at all, you will not be able to check code that runs during compiletime (this isn’t possible in “regular” code as well).

After that has been done, you could use the dialyzer module directly to set up module and PLT pathes, and check the modules you created earlier.

3 Likes