parlour icon indicating copy to clipboard operation
parlour copied to clipboard

Supporting Overloads

Open bmalinconico opened this issue 5 years ago • 4 comments

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

bmalinconico avatar Oct 29 '19 13:10 bmalinconico

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.

AaronC81 avatar Oct 29 '19 19:10 AaronC81

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.

AaronC81 avatar Oct 29 '19 22:10 AaronC81

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

bmalinconico avatar Oct 30 '19 01:10 bmalinconico

This is possible outside of stdlib since Sorbet 0.5.11087 (ref https://github.com/sorbet/sorbet/pull/7412).

bdewater avatar Mar 07 '24 14:03 bdewater