-
Notifications
You must be signed in to change notification settings - Fork 127
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
Merging attributes with annotations fails #1709
Comments
This is by design. When trying to merge two definitions such as this: # rbi/foo.rbi
class Foo
attr_reader :foo; end
end
# lib/foo.rb
class Foo
def foo; end
end Tapioca will see that the shim says it's an attribute accessor yet the code says it's a method and will discard the shim as it indicate it may be out of date. If the actual code uses a method the rbi file must use a method as well or the definition will be discarded. |
I'm not sure that was the exact case we were seeing in Prism. The shims under sig { returns(<%= field.rbi_class %>) }
attr_reader :<%= field.name %> And so is the actual code. Both were defined as attributes, but Tapioca seemed to be dropping them. |
Yeah, at the moment it seems that Tapioca can't see if a method comes from an attribute accessor or not. If you look at the generated RBI for But indeed, we could be more lenient when it comes to merging and allow the merging of the signatures. This raises a question though. Should we keep the |
In Tapioca, we've always defaulted to generating reader/writer methods instead of Basically, you don't get any advantage from using As a result, I think we should:
|
We ran into this for Prism: Shopify/ruby-lsp#1953 (comment) |
Tapioca currently rewrites `attr_reader` methods in RBI files to normal method definitions when merging signatures, but doesn't include the annotations in the merged result. Related issue: Shopify/tapioca#1709 This means that current methods typed with `attr_reader` in RBI files are actually untyped in the merged RBI files. So this commit declares those methods with normal method definitions in the RBI files to work around this issue.
So, my initial inclination here was to first fix the " After looking into this, I don't think that approach is tenable, and I suggest we go right for rewriting The current implementation says that This means they're never merged at all. Whatever was on the "left" side of the comparison, is what was kept.
|
Closing this in favour of #1918, which will make it so that we never emit attributes to begin with. When it's all methods, those will automatically merge correctly, without us needing to do anything special. |
When addressing ruby/prism#1767, I noticed that all of the type annotations associated with
attr_reader
were being lost. I believe we may be incorrectly merging type signatures for attributes.Example:
When Tapioca generates the resulting RBI for
my_gem
, it should include the signatureThe text was updated successfully, but these errors were encountered: