Skip to content

Commit 60692c8

Browse files
committed
Fix type_name_lookup so top-level classes win over nested namesakes
Skipping the ambiguity check when `cm.name == cm.full_name` let a nested class (e.g. `Gem::SafeMarshal::Elements::String`) register itself as the unqualified `String` in `unqualified_names`, which then overwrote the core `String` entry during the final `lookup.merge!`. Remove the skip so top-level classes participate in ambiguity detection — the second sighting now correctly marks the name ambiguous and deletes it from `unqualified_names`, leaving `lookup["String"]` pointing at the core class's path.
1 parent 80a336a commit 60692c8

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

lib/rdoc/store.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,6 @@ def type_name_lookup
358358
all_classes_and_modules.each do |cm|
359359
lookup[cm.full_name] = cm.path
360360
unqualified_name = cm.name
361-
next if unqualified_name == cm.full_name
362361

363362
if ambiguous_names[unqualified_name]
364363
# already known ambiguous, skip

test/rdoc/rdoc_store_test.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,23 @@ def test_type_name_lookup_ambiguous_unqualified_name_excluded
13521352
refute lookup.key?('SubClass')
13531353
end
13541354

1355+
def test_type_name_lookup_top_level_class_wins_over_nested_namesake
1356+
top_level_string = @top_level.add_class RDoc::NormalClass, 'String'
1357+
top_level_string.record_location @top_level
1358+
1359+
nested_string = @top_level.add_class RDoc::NormalClass, 'Gem::Elements::String'
1360+
nested_string.record_location @top_level
1361+
1362+
@s.complete :public
1363+
1364+
lookup = @s.type_name_lookup
1365+
1366+
# Top-level class retains its own path; nested namesake does not
1367+
# hijack the unqualified name.
1368+
assert_equal top_level_string.path, lookup['String']
1369+
assert_equal nested_string.path, lookup['Gem::Elements::String']
1370+
end
1371+
13551372

13561373
def test_merge_rbs_signatures_does_not_overwrite_inline_annotations
13571374
m = RDoc::AnyMethod.new(nil, 'greet')

0 commit comments

Comments
 (0)