rbs icon indicating copy to clipboard operation
rbs copied to clipboard

RBS::InstanceVariableDuplicationError happens on double included module

Open pocke opened this issue 10 months ago • 1 comments

rbs validate shows RBS::InstanceVariableDuplicationError if one class includes a module twice. Is it intentional?

Problem

module M
  @iv: untyped
end

class C
  include M
  include M
end
$ rbs -I. validate
E, [2025-04-07T15:08:43.141421 #23447] ERROR -- rbs: ./test.rbs:2:2...2:14: Duplicated instance variable name `@iv` in `::M` (RBS::InstanceVariableDuplicationError)

    @iv: untyped

Real world example

I realized this problem in the following code in a real Rails application.

module M
  @iv: untyped
end

module X
  include M
end

class C
  include M
  include X
end

Our code base (unfortunately) has such code. The module M is included twice, directly and indirectly.


I guess it can happen in other cases on complex inheritance trees.

Also, the duplication is not harmful. Because these ivar definitions are the same. So I think we can suppress the error in this case.

Even if it should be an error, I think we should fix the error message because it's confusing.

pocke avatar Apr 07 '25 06:04 pocke

There are some possible improvements for this:

  1. Delay error detection after DefinitionBuilder so that users can continue working with the broken definition
  2. Better error message so that users can easily fix the problem

We won't take any action for now. If more user reports this problem, we can disable the validation for now, in 3.9.x.

soutaro avatar Apr 07 '25 06:04 soutaro