diff --git a/lib/rbs/prototype/runtime.rb b/lib/rbs/prototype/runtime.rb index 21cafd8ce..fd40ed893 100644 --- a/lib/rbs/prototype/runtime.rb +++ b/lib/rbs/prototype/runtime.rb @@ -395,7 +395,7 @@ def generate_class(mod) unless decl decl = AST::Declarations::Class.new( name: to_type_name(only_name(mod)), - type_params: [], + type_params: type_params(mod), super_class: generate_super_class(mod), members: [], annotations: [], @@ -449,7 +449,7 @@ def generate_module(mod) unless decl decl = AST::Declarations::Module.new( name: to_type_name(only_name(mod)), - type_params: [], + type_params: type_params(mod), self_types: [], members: [], annotations: [], @@ -504,7 +504,7 @@ def ensure_outer_module_declarations(mod) if outer_module.is_a?(Class) outer_decl = AST::Declarations::Class.new( name: to_type_name(outer_module_name), - type_params: [], + type_params: type_params(outer_module), super_class: generate_super_class(outer_module), members: [], annotations: [], @@ -514,7 +514,7 @@ def ensure_outer_module_declarations(mod) else outer_decl = AST::Declarations::Module.new( name: to_type_name(outer_module_name), - type_params: [], + type_params: type_params(outer_module), self_types: [], members: [], annotations: [], @@ -562,6 +562,15 @@ def type_args(type_name) end end + def type_params(mod) + type_name = to_type_name(const_name(mod), full_name: true) + if class_decl = env.class_decls[type_name.absolute!] + class_decl.type_params + else + [] + end + end + def block_from_ast_of(method) return nil if RUBY_VERSION < '3.1' diff --git a/test/rbs/runtime_prototype_test.rb b/test/rbs/runtime_prototype_test.rb index 25ca941a7..2b7bf6020 100644 --- a/test/rbs/runtime_prototype_test.rb +++ b/test/rbs/runtime_prototype_test.rb @@ -474,4 +474,48 @@ def test_nameerror_message end end end + + class TestTypeParams + class TestTypeParams + end + end + + def test_type_params + SignatureManager.new do |manager| + manager.files[Pathname("foo.rbs")] = <<~RBS + module RBS + class RuntimePrototypeTest < ::Test::Unit::TestCase + class TestTypeParams[unchecked out Elem] + class TestTypeParams + end + end + end + end + RBS + + manager.build do |env| + p = Runtime.new(patterns: ["RBS::RuntimePrototypeTest::TestTypeParams"], env: env, merge: true) + assert_write p.decls, <<~RBS + module RBS + class RuntimePrototypeTest < ::Test::Unit::TestCase + class TestTypeParams[unchecked out Elem] + end + end + end + RBS + + p = Runtime.new(patterns: ["RBS::RuntimePrototypeTest::TestTypeParams::TestTypeParams"], env: env, merge: true) + assert_write p.decls, <<~RBS + module RBS + class RuntimePrototypeTest < ::Test::Unit::TestCase + class TestTypeParams[unchecked out Elem] + class TestTypeParams + end + end + end + end + RBS + end + end + end end