rbs icon indicating copy to clipboard operation
rbs copied to clipboard

rbs prototype rbi should convert T::Enumerator properly

Open connorshea opened this issue 5 years ago • 1 comments
trafficstars

In Sorbet, T::Enumerator only has one argument (e.g. T::Enumerator[String]), but in ruby-signature it has 2.

Right now, this is the input

class Foo
  sig { returns(T::Enumerator[String]) }
  def bar; end
end

And this is what rbs prototype rbi outputs:

class Foo
  def bar: () -> Enumerator[String]
end

The rbs above causes this error when parsed:

::Enumerator expects parameters [Elem, Return], but given args [::String] (Ruby::Signature::InvalidTypeApplicationError)

I'm not 100% sure, but I think T::Enumerator[String] should be converted to Enumerator[String, self] in ruby-signature?

connorshea avatar Apr 14 '20 01:04 connorshea

In the case of StringIO, self is fine, but generally, it depends on what #each returns.

It seems we have two options:

  1. untyped gives a correct type.
  2. nil or self make a runtime test fail, for the case implementation doesn't return them.

I'm going to take option 2...

soutaro avatar Apr 14 '20 01:04 soutaro