Skip to content

Commit c6ecfe5

Browse files
authored
Fix RDoc::Attr#add_alias handling of aliased attribute accessor (#1605)
Ensure aliased attr_accessor attributes have the correct access type ('R' or 'W') instead of always being 'RW'. For more details on the issue being addressed, see #1286 (comment).
1 parent 4889bfe commit c6ecfe5

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/rdoc/code_object/attr.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ def ==(other)
4343
# Add +an_alias+ as an attribute in +context+.
4444

4545
def add_alias(an_alias, context)
46-
new_attr = self.class.new(text, an_alias.new_name, rw, comment, singleton: singleton)
46+
access_type = an_alias.new_name.end_with?('=') ? 'W' : 'R'
47+
new_attr = self.class.new(text, an_alias.new_name, access_type, comment, singleton: singleton)
4748
new_attr.record_location an_alias.file
4849
new_attr.visibility = self.visibility
4950
new_attr.is_alias_for = self

test/rdoc/code_object/attr_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,18 @@ def test_type
187187
assert_equal 'class', @a.type
188188
end
189189

190+
[
191+
['bar', 'baz', 'R'],
192+
['bar=', 'baz=', 'W']
193+
].each do |original_name, new_name, expected_rw|
194+
define_method("test_add_alias_#{new_name}_for_an_attribute_accessor") do
195+
context = RDoc::Context.new
196+
attr = RDoc::Attr.new nil, 'bar', 'RW', ''
197+
an_alias = RDoc::Alias.new nil, original_name, new_name, ''
198+
199+
new_attr = attr.add_alias an_alias, context
200+
201+
assert_equal expected_rw, new_attr.rw
202+
end
203+
end
190204
end

0 commit comments

Comments
 (0)