-
Notifications
You must be signed in to change notification settings - Fork 35
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
Improve some OTP type specs #39
Comments
The long-term solution would be to update these in OTP with more specific types such as |
@zuiderkwast, I agree. We should absolutely try to fix the types on OTP. The plan I outlined above is the short- to medium term solution. |
Where comes the otp code/types into Gradualizer? |
I encourage you to make a pull request with the specs you want to improve in OTP. Preferrably one per OTP application. |
@jachto, the Gradualizer doesn't have any special mechanism for importing types from OTP. The file gradualizer_db handles the lookup of types in other modules, and if you want to dig into the details you can start with the function import_module/2. |
Thanks for the encouragement, @KennethL! It's good to know that you're open to improving the specs. We'll make sure to submit pull request in due course. |
Hello! I think I have similar problems with standard Elixir libraries. Let's say I have a function
Then Gradualizer will say
Where actually t() is Enumerable.t() which is term(). What will be the best solution here? To create |
hi @tim2CF But in general good point about overriding specs. Technically it should be no problem to override an Elixir standard lib spec even in
(Would be nice to have separation and store Elixir overrides in a separate module, even maybe in Elixir syntax) |
I consider this issue Done. Note that it contains "some" in the title. This means that we have reached the goals for a beta version, so let's take 0.1.0! Shall we? (Before we make any new major changes...) |
I wouldn't be opposed to a 0.1.0 version. But I think it's important to point out that polymorphism doesn't work yet. |
Sounds good! Let's finish up stuff in #43, e.g. describing what works and what not. |
There are modules in OTP which have really unfortunate type specs, from the point of view of Gradualizer. Take the function
hd/1
for example. It has the following spec:hd([term()]) -> term()
In Gradualizer, the type
term()
is the top of the subtyping hierarchy, which means that the code that consumes the output ofhd/1
has to account for every kind of value there is! In practice it means that all uses of this function will signal a type error. That's no good! A better type would be:hd([any()]) -> any()
One way to solve this problem is to provide our own type specs for problematic modules in OTP. We could instrument
gradualizer_db
to use its own set of specs instead of these modules.A non-exhaustive list of problematic OTP modules
The text was updated successfully, but these errors were encountered: