Skip to content

Raise when translating generic T.class_of#558

Closed
Morriar wants to merge 1 commit into
mainfrom
at-class-of
Closed

Raise when translating generic T.class_of#558
Morriar wants to merge 1 commit into
mainfrom
at-class-of

Conversation

@Morriar

@Morriar Morriar commented Feb 9, 2026

Copy link
Copy Markdown
Contributor

T.class_of(X)[Y] doesn't have any equivalent in RBS.

When we try to translate such a type to RBS, we just silently drop the generic type param:

translate("T.class_of(Foo)[Bar]") # => singleton(Foo)

I think we should start making it raise so we can catch such cases in our migration process.

One issue with this is that Tapioca will start erroring on files that contain such types. So I'm thinking we may want to make it raise optionally (default = raise) so Tapioca can still generate RBIs without crashing?

@Morriar Morriar requested a review from a team as a code owner February 9, 2026 21:25
This `T.class_of(X)[Y]` doesn't have an equivalent in RBS yet.
We should make it raise to make sure we don't silently remove it.

Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
@Morriar Morriar self-assigned this Feb 9, 2026
Comment thread lib/rbi/rbs_printer.rb

#: (Type::ClassOf type) -> void
def visit_class_of(type)
raise Error, "Unsupported type: #{type} (no RBS equivalent yet)" if type.type_parameter

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of keeping the types that error as sig syntax, accumulate errors and display them at the end? Unproblematic types will still be translated. I think this is also closer to what's best for the end user. Since there's no equivalent they'll either have to change the type or "skip" this translation and continue migrating rest of the types.

One issue with this is that Tapioca will start erroring on files that contain such types. So I'm thinking we may want to make it raise optionally (default = raise) so Tapioca can still generate RBIs without crashing?

Do you mean Spoom or does Tapioca use it too? I think it's fine for spoom srb sigs translate to error but having that control would be nice.

@Morriar

Morriar commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #570, which properly implements bidirectional support now that RBS 4.0.1 ships singleton(X)[Y] syntax.

@Morriar Morriar closed this Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants