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

Add type specifications to all public functions #33

Open
dragonwasrobot opened this issue Apr 10, 2019 · 0 comments
Open

Add type specifications to all public functions #33

dragonwasrobot opened this issue Apr 10, 2019 · 0 comments

Comments

@dragonwasrobot
Copy link

dragonwasrobot commented Apr 10, 2019

It would be nice if all public functions had a @spec type specification so it becomes more obvious from the documentation what types can be given to a function without reading the actual code.

This would also make it possible for dialyzer to do type inference on the code, e.g. I just came across an issue where a RSAPrivateKey was given to ExPublicKey.encrypt_public but the code ended up failing inside ExPublicKey.RSAPublicKey (https://github.com/ntrepid8/ex_crypto/blob/master/lib/ex_public_key/ex_rsa_public_key.ex#L31) with the error

  ** (Protocol.UndefinedError) protocol String.Chars not implemented for #ExPublicKey.RSAPrivateKey<fingerprint_sha256=....>. This protocol is implemented for: Ecto.Time, Ecto.DateTime, Ecto.Date, Decimal, Version, Atom, Integer, Version.Requirement, NaiveDateTime, URI, Date, DateTime, BitString, List, Float, Time

because the line

{:error, "invalid ExPublicKey.RSAPublicKey: #{rsa_public_key}"}

did not use #{inspect rsa_public_key}.

@dragonwasrobot dragonwasrobot changed the title Add @spec to all public functions Add type specifications to all public functions Apr 10, 2019
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

1 participant