Fully qualify extend T::Generic & T::Helpers - #1001
Draft
dejmedus wants to merge 4 commits into
Draft
Conversation
Previously, a TypeError could be raised when we tried to insert an `extend T::Generic` or `extend T::Helpers` into a class that had a generic type member called `T` This commit fully qualifies inserted extends to `::T::Generic` and `::T::Helpers` to prevent this
Previously, `already_extends?` looked through the child nodes to find `extends`. However, as these are wrapped in a `Prism::StatementsNode`, they were not being detected causing a duplicate `extend` to be inserted This commit fixes that by checking statements instead
Generated helper calls and type members are generally inserted at the beginning of a scope. A manually written extend `T::Generic` or extend `T::Helpers` may then appear too late to be useful This commit removes hardcoded `extend`s in favor of inserting where needed, ensuring the correct order without duplicates
dejmedus
force-pushed
the
jb-qualify-extend-t
branch
from
August 6, 2026 22:42
78a7d08 to
e02d892
Compare
dejmedus
force-pushed
the
jb-qualify-extend-t
branch
from
August 6, 2026 23:00
e02d892 to
90f5578
Compare
amomchilov
reviewed
Aug 6, 2026
| unless already_extends?(node, /^(::)?T::Helpers$/) | ||
| extend_with("T::Helpers", into: node, at: insert_pos) | ||
| end | ||
| find_and_remove_existing_extend(node, /^(::)?T::Helpers$/) |
Contributor
There was a problem hiding this comment.
I'm not sure if we should try to fix a pre-existing extend T::Helpers like this.
It's a nice feature in theory, but narrow. There are many other explicit uses of T that would be problematic (T.untyped, T::Boolean, T.any, ...), which we couldn't patch up as easily/reliably. I'm inclined err of inaction, and require people fix their own explicit usages of T.
I suppose the distinction is: who wrote the T?
If our rewriter wrote it, we should be good stewards and ::T it. If devs wrote it explicitly in their own source, they should choose ::T if they want it (or rename their generic arg to not be called T).
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.
Tcan lead toTypeError#990To ensure
T::GenericandT::Helpersdon't conflict with user definedTconstants, we can fully qualify any existing or translator insertedT::Generic/Helpersto::T::This raised a small bug in
already_extends?logic that was previously causing a duplicateextend T::Generic/Helpers