RBS::InstanceVariableDuplicationError happens on double included module
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.
There are some possible improvements for this:
- Delay error detection after
DefinitionBuilderso that users can continue working with the broken definition - 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.