Skip to content

[Bug] rbs-inline fails to generate parent module definitions for nested constants #209

@tommy-314

Description

@tommy-314

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

  1. Set up a project with rbs-inline and steep.

  2. 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
  3. Run bundle exec rbs-inline.

  4. Run bundle exec steep check.

  5. 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
end

Possible 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions