Remove needless Clear bug/weird feature
Hi!
I discovered there's a bug in Remove needless clear
It seems not to work with RETURNING parameters.
Following coding will not trigger any response, but it clearly has pointless clear inside.
Definition
METHODS returning_test IMPORTING true TYPE abap_bool
RETURNING VALUE(result) TYPE abap_bool.
Implementation
METHOD returning_test.
clear result.
result = true.
ENDMETHOD.
Also - i believe in this case:
It should still mention it's not necessary to clear local variables if they are not in a loop and are cleared, but no coding is using them afterwards.
Hi xczar0,
yes, theoretically, if we analyzed program flow, "Remove needless CLEAR" could be much more 'aggressive', removing CLEAR (or even non-initial assignments!) whenever a variable is sure to be assigned again at a later point.
On the other hand, we must keep in mind that ABAP cleaner may be used in the process of writing, so in your second example, maybe someone just clicked Ctrl+4 and then planned to add the following logic between line 53 and 54:
IF it_any IS INITIAL.
RETURN.
ENDIF.
However, I agree that in your first example, "CLEAR result" could actually be removed from method start (no matter how the method continues), because the RETURNING parameter – or rather, all VALUE parameters – are always initialized automatically. So maybe, this would make a good new option ("RETURNING parameter: Action for CLEAR at method start: …"), as long as the method signature is 'in sight' for ABAP cleaner.
Kind regards, Jörg-Michael