Skip to content

Fix #639: don't flag self-aliases used in nested formations#853

Open
bibonix wants to merge 2 commits intoobjectionary:masterfrom
bibonix:fix-redundant-self-639
Open

Fix #639: don't flag self-aliases used in nested formations#853
bibonix wants to merge 2 commits intoobjectionary:masterfrom
bibonix:fix-redundant-self-639

Conversation

@bibonix
Copy link
Copy Markdown
Contributor

@bibonix bibonix commented Apr 26, 2026

@yegor256 this PR fixes #639. Here's what changed and why:

The bug

The example from the issue:

[] > jeff
  $ > self
  [] > say-hello
    stdout self > @

raised The object "self" is redundant and may be inlined. You confirmed it was a false positive.

Root cause

redundant-object.xsl flags any named, non-φ object whose @base reference appears at most once in the program. The parser emits the only reference to self from inside say-hello as <o base="ξ.ρ.self"/>, so the count is 1 and 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 ξ inside say-hello refers to say-hello, not to jeff. 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.yaml with 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 mvn matrix, deep, and reserved jobs are red, but they are red on master too — 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 in MonoLintsTest.lintsProgramCorrectly and PkByXslTest.doesNotDuplicateDefectsWhenMultipleDefectsOnTheSameLine after 45s, which I reproduced locally on a clean checkout of master before applying my fix. Happy to open a separate ticket for the timeouts if useful.

Test plan

  • New pack allows-self-reused-in-nested-formation.yaml reproduces the issue and passes after the fix.
  • All other redundant-object packs still pass (8 allow + 7 catch).
  • Full LtByXslTest passes locally (357 tests, 1 skipped).

Ready for merge.

bibonix added 2 commits April 26, 2026 16:34
…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 ('ξ.ρ.…').
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

redundant-object incorrectly flags object self-reuse in nested formations

1 participant