sign() :: 1 | -1 seems to be an invalid typespec
23Skidoo opened this issue · comments
If my reading of https://hexdocs.pm/elixir/1.12/typespecs.html#literals is correct, negative integer literals are not supported in typespecs.
Despite both the compiler and Dialyzer not complaining, this causes issues sometimes, for example here: pylon/spect#19
Suggestion: change the type of sign to sign() :: :positive | :negative
or sign() :: integer()
Elixir supports negative literals because Erlang does:
Erlang_Integer %% ..., -1, 0, 1, ... 42 ...
https://www.erlang.org/doc/reference_manual/typespec.html
a PR to Elixir typespecs page clarifying this would be appreciated.
if a negative integer literal was unsupported, Elixir compiler should fail to compile a module that uses it.
we cannot change to :positive | :negative
as this would be a breaking change. integer()
would be too broad.
i suspect the spec tool you are using isnt handling negative literals and that is the root cause.
im not on my computer so i cant do more tests but hope it is helpful anyway.
Thanks, this indeed turned out to be a problem with Spect!