larshp/abapOpenChecks

IF in IF - False Positive

hardyp opened this issue · 4 comments

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.

agree, pull requests welcome

works in abaplint,
image

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 suggest just go ahead and opening the PR, its easier to read the code, plus it can be tested

PR added.