ruby / rbs

Type Signature for Ruby
Other
1.92k stars 202 forks source link

rbs prototype rbi should convert T::Enumerator properly #276

Open connorshea opened 4 years ago

connorshea commented 4 years ago

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?

soutaro commented 4 years ago

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...