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

Tapioca does not generate RBI methods for Struct subclasses #1384

Open
bdewater opened this issue Feb 7, 2023 · 2 comments
Open

Tapioca does not generate RBI methods for Struct subclasses #1384

bdewater opened this issue Feb 7, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@bdewater
Copy link
Contributor

bdewater commented Feb 7, 2023

Pulling this out of the Sorbet Slack space and putting it here in case people are surprised by this and can find something about it.

I noticed this pattern in Faraday (ref lostisland/faraday#1489 and lostisland/faraday#1491):

class SSLOptions < Struct.new(:verify_hostname)
  def verify?; end
end

tapioca gem generates RBI methods for verify? but not for verify_hostname/verify_hostname=. The Ruby docs recommend the block form to define a struct, which avoids creating an unused anonymous class in the ancestor chain:

SSLOptions = Struct.new(:verify_hostname) do
  def verify?; end
end

which also happens to help Tapioca pick the verify_hostname/verify_hostname= methods.

It seems in #464 the intent was to fix this, but it seems to have been abandoned. IDK if this is still the plan or that people should just use the Style/StructInheritance Rubocop to avoid the issue from occurring?

@KaanOzkan KaanOzkan added the enhancement New feature or request label Oct 16, 2023
@KaanOzkan
Copy link
Contributor

Looks like we return early here because the method's owner is not the constant (SSLOptions) but an anonymous class.

@paracycle can we use something else other than method.owner to get this information. Maybe special case struct definitions and do constant.instance_methods.include?(method.name)?

@bdewater
Copy link
Contributor Author

Any special handling should also take care of the Ruby 3.2+ Data class. It has the same problem and like for Struct, there's also a Rubocop for it: rubocop/rubocop#11728

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants