Skip to content

RBS::InstanceVariableDuplicationError happens on double included module #2386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
pocke opened this issue Apr 7, 2025 · 1 comment
Open

Comments

@pocke
Copy link
Member

pocke commented Apr 7, 2025

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.

@soutaro
Copy link
Member

soutaro commented Apr 7, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants