Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sign() :: 1 | -1 seems to be an invalid typespec #179

Closed
23Skidoo opened this issue Feb 16, 2022 · 2 comments
Closed

sign() :: 1 | -1 seems to be an invalid typespec #179

23Skidoo opened this issue Feb 16, 2022 · 2 comments

Comments

@23Skidoo
Copy link

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()

@wojtekmach
Copy link
Collaborator

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.

@23Skidoo
Copy link
Author

Thanks, this indeed turned out to be a problem with Spect!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants