Skip to content

Fix false TODO from 'Report unused parameters' for parameters assigned via ASSIGN COMPONENT - #613

Open
0xABCD01 wants to merge 1 commit into
SAP:mainfrom
0xABCD01:fix/612-unused-parameters-assign-component
Open

0xABCD01 wants to merge 1 commit into
SAP:mainfrom
0xABCD01:fix/612-unused-parameters-assign-component

Conversation

@0xABCD01

Copy link
Copy Markdown

Fixes #612.

The "Report unused parameters" rule added a TODO comment such as
" TODO: parameter RS_RESULT is never assigned (ABAP cleaner)
for a RETURNING parameter that is assigned indirectly: a component of the parameter is assigned to a field symbol with ASSIGN COMPONENT ... OF STRUCTURE rs_result TO FIELD-SYMBOL(<...>), and the field symbol is then written to.

The variable analysis already records which field symbols point into a variable's memory and whether those field symbols are written to (VariableInfo.mayHaveIndirectWrites(), also used by the "Make variables FINAL" rule), but UnusedParametersRule only looked at direct assignments. It now also takes indirect writes into account for EXPORTING, CHANGING and RETURNING parameters, so no TODO comment is added in this case. Merely reading through such a field symbol still does not count as an assignment, so the TODO comment continues to be added when the parameter is never actually written.

Tests: six new test cases in UnusedParametersTest cover the scenario from issue #612 (RETURNING parameter), an EXPORTING parameter, a component name supplied in a variable, a field symbol declared with FIELD-SYMBOLS instead of inline, assignment of the whole structure to a field symbol, and a read-only field symbol as a negative case. All 25 tests in UnusedParametersTest pass, and so does the full test suite (3,195 tests).

Disclosure: this contribution was prepared with AI assistance, in line with SAP's guideline for AI-generated code contributions. The commit carries a DCO Signed-off-by.

…d via ASSIGN COMPONENT

The rule only considered direct assignments of a parameter. A parameter that is written through a field symbol - assigned with ASSIGN COMPONENT ... OF STRUCTURE ... TO FIELD-SYMBOL(<...>) or with ASSIGN ... TO FIELD-SYMBOL(<...>) - was therefore wrongly reported as 'never assigned', as described in issue SAP#612.

The variable analysis already records such indirect writes (VariableInfo.mayHaveIndirectWrites(), also used by the 'Make variables FINAL' rule); the rule now takes them into account for EXPORTING, CHANGING and RETURNING parameters. Merely reading through such a field symbol still does not count as an assignment.

Adds six test cases to UnusedParametersTest: the scenario from issue SAP#612, an EXPORTING parameter, a component name supplied in a variable, a field symbol declared with FIELD-SYMBOLS, assignment of the whole structure to a field symbol, and a read-only field symbol as a negative case.

Signed-off-by: Hafiar <289389248+0xABCD01@users.noreply.github.com>
@cla-assistant

cla-assistant Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
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.

"Report unused parameters" does not handle ASSIGN COMPONENT correctly

1 participant