Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/rbi/rbs_printer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,8 @@ def visit_nilable(type)

#: (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.


@string << "singleton("
visit(type.type)
@string << ")"
Expand Down
13 changes: 13 additions & 0 deletions test/rbi/rbs_printer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,19 @@ def e: -> Class[untyped]
RBI
end

def test_print_generic_class_of
rbi = parse_rbi(<<~RBI)
sig { returns(T.class_of(Foo)[Bar]) }
def foo; end
RBI

e = assert_raises(RBI::Error) do
rbi.rbs_string
end

assert_equal("Unsupported type: ::T.class_of(Foo)[Bar] (no RBS equivalent yet)", e.message)
end

def test_print_module_type
rbi = parse_rbi(<<~RBI)
sig { returns(T::Module[String]) }
Expand Down