Commit 5c483d1
authored
Fix false self-referential mixin when bare name matches ancestor namespace (#1672)
# Description
When a module like `A::Enumerable` contains `include Enumerable`, YARD's
lexical resolver walks up the namespace tree, reaches parent namespace
`A`, and finds `A::Enumerable` as the match for the bare name
`Enumerable`. This records the module as including itself — producing
incorrect documentation and potential infinite recursion in
`inheritance_tree`.
This is the valid-Ruby case reported in #1116 (comment):
#1116 (comment)
```ruby
module A
end
module A::Enumerable
include Enumerable # YARD incorrectly resolved this to A::Enumerable itself
end
```
**Fix:** In `RegistryResolver#lookup_by_path`, after a direct-path
lookup returns a result while searching in a *parent* namespace, skip
that result if it equals the original starting namespace. This breaks
the false cycle while leaving all other lookups unaffected (e.g.,
root-level lookups, qualified references).
# Completed Tasks
- [x] I have read the [Contributing Guide][contrib].
- [x] The pull request is complete (implemented / written).
- [x] Git commits have been cleaned up (squash WIP / revert commits).
- [x] I wrote tests and ran `bundle exec rake` locally (if code is
attached to PR).
[contrib]: https://github.com/lsegal/yard/blob/main/CONTRIBUTING.md3 files changed
Lines changed: 28 additions & 0 deletions
File tree
- lib/yard
- spec/handlers
- examples
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
78 | 85 | | |
79 | 86 | | |
80 | 87 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
42 | 49 | | |
43 | 50 | | |
44 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
48 | 62 | | |
49 | 63 | | |
50 | 64 | | |
| |||
0 commit comments