`Code.compile_quoted/2` leaves errors in `spawn_workers/8` errors

Most likely my use-case is not common, but still.

If Code.compile_quoted/2 is called during compile time, it leaves errors in the parallel compiler accumulator, even if rescued. That leads to that when the compilation ends, the compiler itself raises at lib/elixir/lib/kernel/parallel_compiler.ex:458.

  defp spawn_workers([], spawned, waiting, files, result, warnings, errors, state)
       when map_size(spawned) == 0 and map_size(waiting) == 0 do
    [] = errors # bang
    
    [] = files

This was probably not the case at all until Code.with_diagnostics/2 happened to appear. Its sole purpose is to try the code and see how it goes, but if it calls Code.compile_quoted/2 underneath, the whole compilation process fails afterwards, when the compilation has been actually succeeded.

I was unable to figure out how one might un-add the compilation error produced by Code.compile_quoted/2 during compile time, that’s why I would kinda propose an option to Code.with_diagnostics/2 as keep_errors: boolean() to prevent leaking these errors to the main parallel compiler process.

@josevalim would you mind to comment if this needs to be filed as a bug/issue/improvement, or it’s an intended behaviour, please?

Please file an issue report with a small way to reproduce it, thank you!

1 Like

For the record: `Code.compile_quoted/2` leaves errors in parallel compiler accumulator · Issue #13224 · elixir-lang/elixir · GitHub

1 Like

For the record: fixed in 1.17-dev.