Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support type params for known signatures #1408

Merged
merged 1 commit into from
Aug 13, 2023
Merged
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
17 changes: 13 additions & 4 deletions lib/rbs/prototype/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down Expand Up @@ -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: [],
Expand Down Expand Up @@ -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: [],
Expand All @@ -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: [],
Expand Down Expand Up @@ -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'

Expand Down
44 changes: 44 additions & 0 deletions test/rbs/runtime_prototype_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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