WhatsApp / erlang-language-platform

Erlang Language Platform. LSP server and CLI.
https://whatsapp.github.io/erlang-language-platform/
Apache License 2.0
242 stars 19 forks source link

[feature request] make `elp eqwalize` return nonzero on found type errors #20

Open zerth opened 6 months ago

zerth commented 6 months ago

Describe the bug

If invoking eqwalizer results in type errors, it would be nice if elp returned nonzero. A few cases come to mind where that could be beneficial:

  1. eqwalizing in a loop or otherwise against multiple modules and breaking on the first failure
  2. eqwalizing while editing/rebasing a long history of commits (e.g., elp eqwalize X && git rebase --continue)
  3. eqwalizing as a condition of a git bisect run

I know that finding type errors is not a failure of the tool, but think this would make sense from a user perspective.

To Reproduce

-module(some_mod_with_errors).
-spec x(y) -> z; (term()) -> undefined.
x(_) -> z.
elp eqwalize some_mod_with_errors

Expected behavior

% elp eqwalize some_mod_with_errors && echo ok || echo failed
...
failed

Actual behavior

% elp eqwalize some_mod_with_errors && echo ok || echo failed
...
error: incompatible_types
  ┌─ some_mod_with_errors.erl:3:9
  │
4 │ x(_) -> z.
  │         ^ 'z'.
Expression has type:   'z'
Context expected type: 'undefined'

1 ERROR
ok
robertoaloi commented 6 months ago

It makes sense to me. If we want to ensure backward compatibility, we could implement this behaviour via an optional -f (--fail) flag. @alanz @VLanvin opinions?

VLanvin commented 6 months ago

Makes sense to me, but as you said @robertoaloi it should definitely be a flag. There are contexts where we don't want this behaviour.