rbs
rbs copied to clipboard
rbs prototype rbi should convert T::Enumerator properly
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?
In the case of StringIO, self is fine, but generally, it depends on what #each returns.
It seems we have two options:
untypedgives a correct type.nilorselfmake a runtime test fail, for the case implementation doesn't return them.
I'm going to take option 2...