Include "self type" methods like Enumerable#each from RBS files #769
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
RBS has the concept of a 'self type', which is a way to refer to the requirements a class must implement in order to use a mix-in. An example would be the 'each' method, which you must implement before you can import 'Enumerable'.
The implication of this is that is it reasonably safe to assume that anything that includes Enumerable will have this method, which allows 'Enumerable' to be treated as a de-facto superclass of concrete container classes like 'Hash', 'Set' and 'Array' and allow methods to depend on the Enumerable abstract interface and accept a variety of container types.
With this change, we assume that if we receive something with type X, it implements all of its self types. As a result, we won't see typechecking errors when e.g. using #each on an Enumerable.
A future typechecking improvement would double check that the concrete class does implement the self type interface when the receiving type requires it.