ruby / ruby/rbs

Constraints on variables

Open
#559 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Ruby
Stars
2.2k
Forks
256
Avg merge
6d 17h
Merged PRs (30d)
37

Description

It seems that currently the grammar only supports type constraints in the case of module declarations. It would be very useful to be able to constrain type variables, e.g. to require a particular interface.

For example:

interface _Comparable
  def <=>: (untyped other) -> Integer | nil
end

class Heap[Elem : _Comparable]
  def add: (Elem) -> void
end

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the module declaration section linked in docs/syntax.md and the issue’s RBS example. Determine the syntax and behavior needed for constrained type variables, then ensure the Heap[Elem : _Comparable] example is accepted and its constraint is enforced.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.