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

Fix resolving mixins that mix themselves in #1467

Merged
merged 2 commits into from
Apr 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/yard/handlers/ruby/mixin_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ def process_mixin(mixin)
raise YARD::Parser::UndocumentableError unless mixin.ref?
raise YARD::Parser::UndocumentableError if mixin.first.type == :ident

case obj = Proxy.new(namespace, mixin.source)
when ConstantObject # If a constant is included, use its value as the real object
obj = Proxy.new(namespace, obj.value, :module)
if mixin.type == :var_ref && mixin[0] == s(:kw, "self")
obj = namespace
else
obj = Proxy.new(namespace, mixin.source, :module)
case obj = Proxy.new(namespace, mixin.source)
when ConstantObject # If a constant is included, use its value as the real object
obj = Proxy.new(namespace, obj.value, :module)
else
obj = Proxy.new(namespace, mixin.source, :module)
end
end

rec = recipient(mixin)
Expand All @@ -44,7 +48,7 @@ def process_mixin(mixin)
end

def recipient(mixin)
if statement[0].type == :const_path_ref
if statement[0].type == :const_path_ref || statement[0].type == :top_const_ref
Proxy.new(namespace, statement[0].source)
elsif statement[0].type == :var_ref && statement[0][0] != s(:kw, "self")
statement[0][0].type == :const ?
Expand Down
13 changes: 13 additions & 0 deletions spec/handlers/examples/mixin_handler_001.rb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,16 @@ end

module FromConstant; end
FromConstant.include A

module Foo
end

module MixMySelfIn
Foo.include(self)
end

module Nested
module Foo
::Foo.include(self)
end
end
4 changes: 4 additions & 0 deletions spec/handlers/mixin_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ class D1; class E1; module F1; end end end
expect(P('A1::B1::C1').instance_mixins).to eq [P('D1::E1::F1')]
end

it "resolves modules that mix themselves in" do
expect(Registry.at('Foo').mixins).to match_array [P('MixMySelfIn'), P('Nested::Foo')]
end

it "ensures the recipient is loaded from another file" do
# 002 includes a module into a module defined in 003
parse_file [:mixin_handler_002, :mixin_handler_003], __FILE__
Expand Down