Conversation
9347b86 to
a1bcaff
Compare
| result = move(node); | ||
| }, | ||
| [&](parser::Send *send) { | ||
| if (!parser::MK::isVisibilitySend(send)) { |
There was a problem hiding this comment.
Why do we need this condition, can't we just visit them?
There was a problem hiding this comment.
From my understanding, a method like this:
#: (Integer) -> void
private def method1(x)
T.reveal_type(x)
endhas a DefMethod node and a Send node from the private keyword.
First, signaturesTarget() finds the DefMethod → creates signature.
Then, rewriteNodes processes the Send arguments → finds same DefMethod → creates duplicate signature.
This results in "Unused type annotation" errors if we do not include this check.
There was a problem hiding this comment.
I'm not sure I follow.
The comment should have been associated to the def:
sorbet/rbs/CommentsAssociator.cc
Line 456 in ad5cc43
So this means we're visiting the same node twice?
There was a problem hiding this comment.
Ok, it seems we're visiting the send arg once through the body of the class, then a second type by visiting the send itself.
I wonder if we should instead attach the comment to the send in commentsAssociator so we don't have to check isVisibilitySend 3 times?
There was a problem hiding this comment.
Thanks for the suggestion! I looked into this with @KaanOzkan, and if we associate comments with the Send node instead of the method def, the rewriter would need to extract the comment from the Send and apply it to the DefMethod in args[0]. This cross-node processing would add some complexity compared to the current approach. I can explore this if you think we should go with this route, or I can open the PR in Sorbet and see what they say.
There was a problem hiding this comment.
I've prototyped it here: #436, let me know what you think!
RBS signatures weren't being recognized when method definitions were nested inside `send` node arguments (e.g., `A.prepend(Module.new do...`). The SigsRewriter now traverses into non-visibility send node arguments to process method definitions and convert their associated RBS comments into signature nodes. Visibility modifier sends are skipped to prevent double-processing.

Fix RBS signature recognition in send node contexts
Ticket: https://github.com/Shopify/team-ruby-dx/issues/1451
Solution
SigsRewriter changes:
private def method_name) to prevent double-processing, since those method definitions are already handled directly by the main AST traversalExample