Skip to content

Commit f741032

Browse files
committed
Handle aliases in RBI generation
1 parent 329e187 commit f741032

3 files changed

Lines changed: 501 additions & 3 deletions

File tree

rakelib/typecheck.rake

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,32 @@ namespace :typecheck do
138138
method.sigs << sig
139139
end
140140
end
141-
when RBS::AST::Members::Alias, RBS::AST::Members::InstanceVariable,
142-
RBS::AST::Declarations::Interface, RBS::AST::Declarations::TypeAlias
141+
when RBS::AST::Members::Alias
142+
case [node.new_name, node.old_name]
143+
when [:dispatch, :visit]
144+
parent <<
145+
RBI::Method.new("dispatch", visibility: @visibility, comments: compile_comments(node)) do |method|
146+
method.add_param("node")
147+
method.sigs <<
148+
RBI::Sig.new(
149+
params: [RBI::SigParam.new("node", RBI::Type.nilable(RBI::Type.simple("Node")))],
150+
return_type: RBI::Type.untyped
151+
)
152+
end
153+
when [:script_lines, :source_lines],
154+
[:find, :breadth_first_search],
155+
[:find_all, :breadth_first_search_all],
156+
[:deconstruct, :child_nodes]
157+
found = parent.nodes.find { |child| child.is_a?(RBI::Method) && child.name == node.old_name.name }
158+
parent <<
159+
found.dup.tap do |method|
160+
method.name = node.new_name.name
161+
method.comments = compile_comments(node)
162+
end
163+
else
164+
raise
165+
end
166+
when RBS::AST::Members::InstanceVariable, RBS::AST::Declarations::Interface, RBS::AST::Declarations::TypeAlias
143167
# skip
144168
else
145169
raise
@@ -277,7 +301,7 @@ namespace :typecheck do
277301
end
278302

279303
desc "Generate RBIs from RBSs"
280-
task rbi: :rbs_inline do
304+
task rbi: :templates do
281305
with_gemfile do
282306
require "fileutils"
283307
require "rbs"

rbi/generated/prism/dispatcher.rbi

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)