Skip to content

Fix #640: recognize chained-dot usage of $-aliased attributes#859

Open
bibonix wants to merge 2 commits intoobjectionary:masterfrom
bibonix:fix-640
Open

Fix #640: recognize chained-dot usage of $-aliased attributes#859
bibonix wants to merge 2 commits intoobjectionary:masterfrom
bibonix:fix-640

Conversation

@bibonix
Copy link
Copy Markdown
Contributor

@bibonix bibonix commented May 3, 2026

Fixes #640.

The bug

redundant-object flags self as redundant for the snippet from the issue:

[bts] > bytes-as-input
  [size] > read
    ((input-block bts --).read size).self > @
    [data buffer] > input-block
      buffer > @
      $ > self

The XMIR shows the only reference to self as <o base=".self"/> (a chained method call on the result of (input-block bts --).read size), but the existing usage XPath only matches @base values starting with ξ:

^ξ(?:\.ρ)*\.self(?:\.[\w-]+)*$

So the count of usages stays at 0, the <= 1 condition fires, and the lint emits "The object self is redundant and may be inlined" — but inlining is impossible here, since self aliases $ and (...).$ is not valid EO.

Fix

src/main/resources/org/eolang/lints/misc/redundant-object.xsl: add a second regex matching the chained-dot usage form (^\.<name>(?:\.[\w-]+)*$), and skip the warning when the candidate's @base='ξ' and at least one chained-dot usage exists. Same-level redundant aliases stay flagged because their usages still appear under the ξ.<name> shape, so all existing catches-* packs continue to fire.

Test

New pack allows-self-used-via-chained-dot.yaml reproduces the issue example and asserts zero defects. Without the XSL change it fails with the "self is redundant" warning; with the change it passes. The full LtByXslTest#testsAllLintsByEo parameterized suite (346 packs) is green.

bibonix added 2 commits May 3, 2026 04:24
… usage

The redundant-object lint flags 'self' as redundant when it is reached
via a chained dot reference like '(...).self', because the usage XPath
only matches '@base' values prefixed with 'xi(.rho)*'. The new pack
exercises exactly that shape and currently fails.
When an attribute is declared as a $-alias (`$ > name`) and the only
reference to it appears as a chained method call (`(...).name`), the
parser emits the usage as `<o base=".name"/>`, which the previous
`^ξ(?:\.ρ)*\.<name>(?:\.[\w-]+)*$` regex never matched. The lint
therefore counted zero usages and flagged the attribute as redundant,
even though inlining it (`(...).$`) is not valid EO.

Add a second regex matching the chained-dot form and suppress the
warning when the candidate is a $-alias and at least one such usage
exists. Same-level redundant aliases stay flagged because their usages
still appear under the `ξ.<name>` form.
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 lint rule fails to recognize object usage above its declaration level

1 participant