parlour
parlour copied to clipboard
Supporting Overloads
Sorbet now supported overloaded method signatures.
Poking around parlour I do not see a way to do this yet. If we are not yet able to generate multiple sigs per method, I would like to have a chat about options. If they have not been implemented by the time I need them, I'll add them myself if we can agree on an appropriate pattern.
My first instinct is:
@node.create_method('foo', the_rest) do |method|
method.add_signature(takes_the_same_arguments_less_the_name)
end
I didn't know Sorbet supports overloads now - that's great!
Parlour doesn't support this currently. I'm happy to look at implementing overloads, but we do indeed need to decide on a pattern for implementing them. I'm think the call structure you've proposed is probably the best way of doing it.
It might be worth restructuring some of how Parlour works to make the implementation more elegant - perhaps breaking a Signature
object out of the existing Method
object, or something like that.
May I ask if you're currently using overloads in a codebase, @bmalinconico? It seems that they aren't generally available for use in Sorbet yet, and I can't get them to work on sorbet.run.
Ah looks like overloads are only allowed in the stdlib and that test file
constexpr string_view whitelistedTest = "overloads_test.rb"sv;
if (((file.isPayload() || file.isStdlib()) && owner != Symbols::root() &&
(owner != Symbols::Object() || sigLoc.data(*this).isStdlib())) ||
FileOps::getFileName(file.path()) == whitelistedTest) {
return true;
}
Hopefully that means it is coming soon
This is possible outside of stdlib since Sorbet 0.5.11087 (ref https://github.com/sorbet/sorbet/pull/7412).