Skip to content

Fix AnyMethod#is_alias_for for nil singleton #590

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

Merged
merged 1 commit into from
Jan 23, 2018
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
8 changes: 7 additions & 1 deletion lib/rdoc/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,13 @@ def find_local_symbol(symbol)
# Finds a method named +name+ with singleton value +singleton+.

def find_method(name, singleton)
@method_list.find { |m| m.name == name && m.singleton == singleton }
@method_list.find { |m|
if m.singleton
m.name == name && m.singleton == singleton
else
m.name == name && !m.singleton && !singleton
end
}
end

##
Expand Down
13 changes: 13 additions & 0 deletions test/test_rdoc_any_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,19 @@ def test_marshal_load_aliased_method
assert aliased_method.display?
end

def test_marshal_load_aliased_method_with_nil_singleton
aliased_method = Marshal.load Marshal.dump(@c2_a)

aliased_method.store = @store
aliased_method.is_alias_for = ["C2", nil, "b"]

assert_equal 'C2#a', aliased_method.full_name
assert_equal 'C2', aliased_method.parent_name
assert_equal '()', aliased_method.params
assert_equal @c2_b, aliased_method.is_alias_for, 'is_alias_for'
assert aliased_method.display?
end

def test_marshal_load_class_method
class_method = Marshal.load Marshal.dump(@c1.method_list.first)

Expand Down
8 changes: 8 additions & 0 deletions test/test_rdoc_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,14 @@ def test_find_local_symbol
assert_equal @c2_c3, @c2.find_local_symbol('C3')
end

def test_find_method
loaded_c2 = Marshal.load Marshal.dump @c2
assert_equal @c2_a, loaded_c2.find_method('a', false)
assert_equal @c2_b, loaded_c2.find_method('b', false)
assert_equal @c2_a, loaded_c2.find_method('a', nil)
assert_equal @c2_b, loaded_c2.find_method('b', nil)
end

def test_find_method_named
assert_equal true, @c1.find_method_named('m').singleton
end
Expand Down