Fix #639: don't flag self-aliases used in nested formations#853
Open
bibonix wants to merge 2 commits intoobjectionary:masterfrom
Open
Fix #639: don't flag self-aliases used in nested formations#853bibonix wants to merge 2 commits intoobjectionary:masterfrom
bibonix wants to merge 2 commits intoobjectionary:masterfrom
Conversation
…bjectionary#639) Reproduces the bug where redundant-object lint incorrectly flags a self-alias ('$ > self') as redundant when it's referenced from a nested formation. The reference 'ξ.ρ.self' from inside say-hello counts as the single usage that triggers the count<=1 threshold.
The redundant-object lint flagged '$ > self' as redundant when the only reference came from a nested formation (e.g. 'ξ.ρ.self' from inside a child object). Inlining '$' into a nested scope changes its meaning, since 'ξ' there refers to the child, not the parent. Skip the check when the candidate's @base is 'ξ' and at least one usage is through a parent hop ('ξ.ρ.…').
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@yegor256 this PR fixes #639. Here's what changed and why:
The bug
The example from the issue:
raised
The object "self" is redundant and may be inlined. You confirmed it was a false positive.Root cause
redundant-object.xslflags any named, non-φobject whose@basereference appears at most once in the program. The parser emits the only reference toselffrom insidesay-helloas<o base="ξ.ρ.self"/>, so the count is1and the lint fires.The match itself is fine — the suggested remediation (inlining) is what would be unsafe.
self's body is$(@base="ξ"), and inlining$into a nested formation changes its meaning, sinceξinsidesay-hellorefers tosay-hello, not tojeff. The fix has to suppress the warning specifically for that shape.Fix
src/main/resources/org/eolang/lints/misc/redundant-object.xsl: add a second regex that captures only references reached through a parent hop (^ξ\.ρ(?:\.ρ)*\.<name>(?:\.[\w-]+)*$), and skip the warning when the candidate's@base="ξ"and at least one of its usages matches that nested-reference regex. Same-level usages of a$-alias remain flagged because they can be safely inlined.Test
Added pack
redundant-object/allows-self-reused-in-nested-formation.yamlwith the exact snippet from the issue, asserting zero defects. It fails on the pre-fix XSL and passes after.CI
Lint-only checks (
qulice,pdd,ort,xcop,yamllint,markdown-lint,vale,actionlint,shellcheck,reuse,copyrights,bashate,typos,labeler) all pass.The
mvnmatrix,deep, andreservedjobs are red, but they are red onmastertoo — every push since 2026-04-25 has failed them (run 24960783274 on master, your most recent push, fails the same way). The failures are timeouts inMonoLintsTest.lintsProgramCorrectlyandPkByXslTest.doesNotDuplicateDefectsWhenMultipleDefectsOnTheSameLineafter 45s, which I reproduced locally on a clean checkout ofmasterbefore applying my fix. Happy to open a separate ticket for the timeouts if useful.Test plan
allows-self-reused-in-nested-formation.yamlreproduces the issue and passes after the fix.redundant-objectpacks still pass (8 allow + 7 catch).LtByXslTestpasses locally (357 tests, 1 skipped).Ready for merge.