ruby / ruby/rbs

Handle INFINITY as literal

Open
#1,382 2 comments 0 reactions 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

Currently, it's impossible to use Float::Infinity as a literal in signatures:

 def initialize: (Integer | Float::Infinity bytesize) -> void
#=> RuntimeError: Neutered Exception RBS::Test::Tester::TypeError: TypeError: [MyClass#initialize] ArgumentTypeError: expected `::Integer | Float::Infinity` (bytesize) but given `Inf
inity`
 def initialize: (Integer | Infinity bytesize) -> void
#=> RuntimeError: Neutered Exception RBS::Test::Tester::TypeError: TypeError: [MyClass#initialize] ArgumentTypeError: expected `::Integer |Infinity` (bytesize) but given `Inf
inity`
 def initialize: (Integer | Float::INFINITY bytesize) -> void
#=> TypeError: class or module required

Consider the case of a buffer with bounded or unbounded size, common in network software. In such a case, you want to tag the buffer size precisely (as an integer), or leave it open-ended (with Float::INFINITY). It's unacceptable that, for instance, 3.4 is set as buffer size; however, as per the current constraint, the only way to set a signature that would be tolerant to infinity would be:

 def initialize: (Integer | Float bytesize) -> void

which would tolerate other floats.

I don't know whether there are other variables handled specially, but I'd argue that this Infinity should be handled the same way as 4in any given rbs signature.

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

No file or test is named in the issue. Reproduce the Float::Infinity and Infinity signature examples, then trace the parser and type-checking entry points that handle literal types. Done means a signature accepts infinity as a distinct literal without accepting arbitrary Float values.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.