ruby / ruby/rbs

[Feature request] Introduce constant type

Open
#623 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

When I've recently opened PR to add signatures of the Parallel gem on the ruby/gem_rbs_collection repository, I encounter the following difficulty:

# Ruby code
items = [1, 2, 3]
Parallel.all?(-> { items.pop || Parallel::Stop }) { |item| item.size == 1 }

# RBS (short version)
module Parallel
  Stop: Object

  # `T | Stop` should be better than `T | untyped`.
  def self.all?: [T] (Enumerable[T] | (^() -> T | untyped) array) { (T) -> boolish } -> bool
end

As you see above, we now cannot use Parallel::Stop as a type.

Supporting such a type signature might be useful, but what do you think?


This proposal is thanks to @pocke. Please refer to https://github.com/ruby/gem_rbs_collection/pull/21#discussion_r587286192 for details.

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 issue's Parallel example and the linked gem_rbs_collection discussion to understand how a constant such as Parallel::Stop is currently parsed and represented. Determine the design needed for using that constant as a type, then add coverage for the example and verify that the signature can use Parallel::Stop instead of untyped.

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
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.