Skip to content
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

Handle active support concern's recursive nature #547

Open
vinistock opened this issue Dec 13, 2024 · 0 comments
Open

Handle active support concern's recursive nature #547

vinistock opened this issue Dec 13, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@vinistock
Copy link
Member

This might require some infrastructure changes and new APIs in the Ruby LSP side, but we came to realize that there's one aspect of concerns we are unable to match with the current approach.

If a concern includes another concern which defines class methods, those class methods are recursively extended to all other including concerns. For example:

module ConcernWithClassMethods
  extend ActiveSupport::Concern

  module ClassMethods
    def foo; end
  end
end

module OtherConcern
  extend ActiveSupport::Concern
  include ConcernWithClassMethods
end

OtherConcern.foo # ok!

module YetAnotherConcern
  extend ActiveSupport::Concern
  include OtherConcern
end

YetAnotherConcern.foo # ok!

class Bar
  include YetAnotherConcern
end

Bar.foo # ok!

This is a bit challenging to fix with our current architecture because ancestor linearization is done all lazily for better performance and in this particular example, ancestors of the attached class alter the ancestors of the singleton class.

That is, you need to linearize the ancestors of Bar to discover that Bar::<Class:Bar> inherits from ConcernWithClassMethods::ClassMethods. We may need some way to have concerns mark the namespaces that include them with some flag telling the algorithm that, for those namespaces, you have to first linearize the attached class in order to accurately linearize the singleton class.

@vinistock vinistock added the bug Something isn't working label Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant