Fix #640: recognize chained-dot usage of $-aliased attributes#859
Open
bibonix wants to merge 2 commits intoobjectionary:masterfrom
Open
Fix #640: recognize chained-dot usage of $-aliased attributes#859bibonix wants to merge 2 commits intoobjectionary:masterfrom
bibonix wants to merge 2 commits intoobjectionary:masterfrom
Conversation
… 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.
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.
Fixes #640.
The bug
redundant-objectflagsselfas redundant for the snippet from the issue:The XMIR shows the only reference to
selfas<o base=".self"/>(a chained method call on the result of(input-block bts --).read size), but the existing usage XPath only matches@basevalues starting withξ:So the count of usages stays at 0, the
<= 1condition fires, and the lint emits "The object self is redundant and may be inlined" — but inlining is impossible here, sinceselfaliases$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 existingcatches-*packs continue to fire.Test
New pack
allows-self-used-via-chained-dot.yamlreproduces 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 fullLtByXslTest#testsAllLintsByEoparameterized suite (346 packs) is green.