rbs icon indicating copy to clipboard operation
rbs copied to clipboard

Handle INFINITY as literal

Open HoneyryderChuck opened this issue 2 years ago • 2 comments

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.

HoneyryderChuck avatar Jul 19 '23 23:07 HoneyryderChuck

Some APIs use nil as integer infinity, others rëuse Float::Infinity. But yeah, nil folks would need something else for negative infinity.

ParadoxV5 avatar Jul 27 '23 20:07 ParadoxV5

How about allowing constants to be used as literals, not just those of Float? 🤔

ParadoxV5 avatar Jul 27 '23 23:07 ParadoxV5