From e1e6b0b16acd47c7872c2520e7bfdf8c74867004 Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Mon, 9 Feb 2026 16:21:25 -0500 Subject: [PATCH] Raise when trying to translate generic singleton 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 --- lib/rbi/rbs_printer.rb | 2 ++ test/rbi/rbs_printer_test.rb | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/rbi/rbs_printer.rb b/lib/rbi/rbs_printer.rb index a6127a96..009431af 100644 --- a/lib/rbi/rbs_printer.rb +++ b/lib/rbi/rbs_printer.rb @@ -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 + @string << "singleton(" visit(type.type) @string << ")" diff --git a/test/rbi/rbs_printer_test.rb b/test/rbi/rbs_printer_test.rb index b90344f0..48ebd296 100644 --- a/test/rbi/rbs_printer_test.rb +++ b/test/rbi/rbs_printer_test.rb @@ -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]) }