Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit declaring .new constructors for abstract classes in generated RBI files #1507

Closed
olivier-thatch opened this issue May 22, 2023 · 1 comment · Fixed by #1524
Closed
Labels
bug Something isn't working

Comments

@olivier-thatch
Copy link
Contributor

olivier-thatch commented May 22, 2023

Following this recent change in Sorbet (released in 0.5.10810), RBI files generated by Tapioca for third-party gems went from declaring class constructors like this:

class Foo
  # source://sorbet-runtime/0.5.10795/lib/types/private/abstract/declare.rb#37
  def initialize(*args, **_arg1, &blk); end
end

to being declared like this:

class Foo
  class << self
    # source://sorbet-runtime/0.5.10838/lib/types/private/abstract/declare.rb#37
    def new(*args, **_arg1, &blk); end
  end
end

This causes Sorbet to type the return value of Foo.new as T.untyped: https://sorbet.run/#%23%20typed%3A%20true%0A%0Aclass%20Foo%0A%20%20%23%20def%20initialize%28*args%2C%20**_arg1%2C%20%26blk%29%3B%20end%0A%0A%20%20class%20%3C%3C%20self%0A%20%20%20%20def%20new%28*args%2C%20**_arg1%2C%20%26blk%29%3B%20end%0A%20%20end%0Aend%0A%0Afoo%20%3D%20Foo.new%20%0AT.reveal_type%28foo%29%20%23%20revealed%20type%3A%20T.untyped%0A

I asked about this in the Sorbet Discord and @jez (author of the Sorbet PR that caused this change) said that ideally, Tapioca should not generate a signature at all for constructors in abstract classes:

IMO we should hide these definitions in tapioca-generated RBI files. i’d suggest making a feature request against tapioca
Either the generated RBI needs to have a sig that declares the return type being T.attached_class, or better they need to omit declaring a signature for new so that Sorbet’s intrinsic new -> initialize forwarding works

@jez
Copy link

jez commented May 22, 2023

To be clear: not all constructors, just the ones in abstract classes

@olivier-thatch olivier-thatch changed the title Omit declaring .new constructors in generated RBI files Omit declaring .new constructors for abstract classes in generated RBI files May 22, 2023
@KaanOzkan KaanOzkan added the bug Something isn't working label May 24, 2023
@KaanOzkan KaanOzkan added this to the Sorbet in all Ruby projects milestone May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants