Method overload narrowing
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 2.2k
- Forks
- 256
- Avg merge
- 6d 17h
- Merged PRs (30d)
- 37
Description
I request a notation for method overload narrowing, such that subtype args narrow supertype args.
The intent is so the return type of supertype overloads not longer need to explicitly include those of narrower overloads.
E.g., TrueClass#& example from prior brief discussion on Discord:
def &: (false? rhs) -> false
| (untyped rhs) -> true
Contrast with our current compromise:
https://github.com/ruby/rbs/blob/45b34bd9bf9a2b6872ae832f6a344b23dc75ec3d/core/true_class.rbs#L28-L29
This new solution enables us to type the result for truthy args without needing a “difference type” type truthy = top - false?.
In fact, this is possibly the only practical use case for “difference types”.
I’ve considered moving this focus to Steep but decided that the entire RBS ecosystem could use this.
For example, https://github.com/ruby/rbs/issues/1874#issuecomment-2155458884 finally encouraged me to formally file this issue.
Though it is backward-incompatible to change the semantics of | set by yore, we can instead introduce an new, alternative syntax, such as the tokens:
-
&(from #566) -
:(from the aformentioned Discord discussion) -
||
- Relates to, but does not resolve: #1822
- Summon: @sampersand (replied to me in the aformentioned Discord)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with core/true_class.rbs at the linked overload definition and compare its current compromise with the proposed narrowing example. Review the alternatives (&, :, and ||) and determine the syntax and semantics needed for subtype arguments to narrow supertype overloads; done means the project has an agreed design for this feature.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100