abapOpenChecks icon indicating copy to clipboard operation
abapOpenChecks copied to clipboard

IF in IF - False Positive

Open hardyp opened this issue 4 years ago • 1 comments
trafficstars

The following code:- image

Generates the following error:-

image

Unless I am missing something obvious, if the IF/ENDIF block in the middle contains an ELSE statement then the code cannot be reduced, unless you repeat the outer logical expression in the lines in the IF/ELSE/ENDIF construct.

hardyp avatar Oct 09 '21 00:10 hardyp

agree, pull requests welcome

works in abaplint, image

larshp avatar Oct 09 '21 04:10 larshp

I think a small change at Check_01 -> Method contains_else to also look for else-if branch might help.

  • Unit test results after adding a new scenario Untitled (2)

Adding below code: IF lo_structure->get_type( ) = zcl_aoc_scan=>gc_structure_statement-else or lo_structure->get_type( ) = zcl_aoc_scan=>gc_structure_statement-elseif . All test pass post-changes.

Untitled

Let me know if this works, I will add PR.

Dwivedirahul44 avatar Oct 19 '22 08:10 Dwivedirahul44

@Dwivedirahul44 suggest just go ahead and opening the PR, its easier to read the code, plus it can be tested

larshp avatar Oct 19 '22 08:10 larshp

PR added.

Dwivedirahul44 avatar Oct 19 '22 09:10 Dwivedirahul44