Place generic extend last - #1019
Open
vinistock wants to merge 1 commit into
Open
Conversation
KaanOzkan
reviewed
Aug 31, 2026
|
|
||
| if body.is_a?(Prism::StatementsNode) | ||
| last_extend = body.body.reverse_each.find do |node| | ||
| node.is_a?(Prism::CallNode) && node.message == "extend" && !node.receiver |
Contributor
There was a problem hiding this comment.
Technically we could have a receiver with self.extend right? We could also have a conditional call extend Foo if x which seems to be a Prism::IfNode. Rare to see though, so your call if you want to support it.
| extend OtherThing; extend ::T::Generic; Elem = type_member | ||
| end | ||
| RUBY | ||
| ) |
Contributor
There was a problem hiding this comment.
It might be good to add a test for an extend with an inline comment. I'm working on another translator feature and inline comments caught me off guard.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When we re-write RBS generic namespaces, we place the
extend T::Genericfirst, in the very beginning of the body. This means that they appear last in the singleton class' ancestor chain, which makes it very easy to bypass Tapioca's patches for tracking generic type parameters.That's enough to bypass the patch because
extend T::Genericappears beforeextend Patch, which means the singleton ancestors are[<Something>, <Patch>, <T::Generic>...]. This breaks Tapioca RBI generation for generics.Trying to ensure that Tapioca can always generate regardless of
[]being overridden is not super straight forward, so I propose we flip the rewriter instead. This PR placesextend T::Genericimmediately after the lastextendin a scope's body.The idea is simply to change the insert position, which already fixes the issue, but then it also means we need to be a touch smarter about when to add line breaks in the body.