-
Notifications
You must be signed in to change notification settings - Fork 22
Description
Describe the bug
When rbs-inline generates an RBS file for a nested constant (e.g., Foo::Bar::Baz), it does not automatically create the necessary parent module definitions (Foo and Foo::Bar) in a separate RBS file.
This leads to a RBS::UnknownTypeName error when running steep check, because the parent types are not found.
Version
- rails (7.0.8.7)
- rbs (3.9.4)
- rbs-inline (0.11.0)
- steep (1.10.0)
To Reproduce
-
Set up a project with
rbs-inlineandsteep. -
Create a Ruby file with a nested class, without a separate module definition:
# app/models/foo/bar/baz.rb # rbs_inline: enabled class Foo::Bar::Baz # @rbs () -> String def hello "world" end end
-
Run
bundle exec rbs-inline. -
Run
bundle exec steep check. -
This command fails with the following error.
sig/generated/models/foo/bar/baz.rbs:3:0: [error] Cannot find type `::Foo::Bar`
│ Diagnostic ID: RBS::UnknownTypeName
│
└ class Foo::Bar::Baz
~~~~~~~~~~~~~~~~~~~Expected behavior
rbs-inline should automatically generate the parent module definitions needed for a type checker to run without error.
For the example above, it should generate:
# sig/generated/models/foo.rbs
module Foo
end
# sig/generated/models/foo/bar.rbs
module Foo::Bar
endPossible solutions
I believe the fix would be to modify the RBS generation logic to recursively check and generate RBS files for all parent modules of a given constant, if they don't already exist.