Fully qualify T and NilClass references in generated RBI output#2556
Draft
sambostock wants to merge 1 commit intomainfrom
Draft
Fully qualify T and NilClass references in generated RBI output#2556sambostock wants to merge 1 commit intomainfrom
sambostock wants to merge 1 commit intomainfrom
Conversation
When a class defines a type member named `T` (e.g., via `#: [T]` in RBS), Tapioca's generated RBI files contained unqualified `T::Boolean`, `T.nilable(...)`, etc. These resolve to the type member instead of Sorbet's `::T` module, causing type-checking errors. This commit qualifies all `T` references as `::T` and `NilClass` as `::NilClass` in generated RBI output. These types come from RBS translations (e.g., `bool` → `T::Boolean`, `nil` → `NilClass`) and unambiguously always refer to the top-level constants. Changes: - Add qualification regex to `sanitize_signature_types` as a catch-all for type strings produced by Sorbet's `.to_s` - Update all hardcoded type string literals across DSL compilers/helpers - Qualify `.to_s` output on Sorbet types in gem pipeline listeners - Update `as_nilable_type` to produce `::T.nilable(...)` - Update all test expectations to match qualified output Co-Authored-By: Brad Lindsay <brad.lindsay@shopify.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
72556e0 to
32100bd
Compare
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.
Summary
Fully qualifies
Treferences as::TandNilClassas::NilClassin all generated RBI output.When a class defines a type member named
T(e.g., via#: [T]in RBS), unqualifiedT::Boolean,T.nilable(...), etc. in generated RBI resolve to the type member instead of Sorbet's::Tmodule, causing type-checking errors. These types come from RBS translations (bool→T::Boolean,untyped→T.untyped,nil→NilClass) and unambiguously always mean the top-level constants.Navigating the diff
Tip
Most of this diff is mechanical
T→::TandNilClass→::NilClassstring literal replacements. The interesting logic changes are in a handful of files:Core qualification logic:
lib/tapioca/helpers/rbi_helper.rb— Adds catch-all regex tosanitize_signature_typesthat qualifiesT::→::T::,T.→::T., andNilClass→::NilClass. Updatesas_nilable_typeto emit::T.nilable(...).Places that called
.to_son Sorbet runtime types (producing unqualified strings):lib/tapioca/dsl/helpers/active_model_type_helper.rb— Applies qualification regex totype.to_soutputlib/tapioca/dsl/helpers/graphql_type_helper.rb— IncludesRBIHelper, routesreturn_type.to_sthroughsanitize_signature_typeslib/tapioca/gem/listeners/sorbet_required_ancestors.rb— Routesancestor.to_sthroughsanitize_signature_typeslib/tapioca/sorbet_ext/generic_name_patch.rb— Routes type variable bounds.to_sthroughsanitize_signature_typesAvoided double-qualification:
lib/tapioca/dsl/compilers/identity_cache.rb—COLLECTION_TYPElambda updated to not blindly prepend::when the type string is already qualifiedEverything else in
lib/andspec/is mechanicals/T::/::T::/ands/T\./::T./in string literals and test expectations.Test plan
tapioca dslon a project with#: [T]generics to confirm the fix🤖 Generated with Claude Code