abapOpenChecks icon indicating copy to clipboard operation
abapOpenChecks copied to clipboard

Check suggestion - Predicate function return type in IF expression

Open nomssi opened this issue 3 years ago • 1 comments

We can use a predicate method call IS_EOF( ) in an IF expression as

          IF is_eof( ).
            str = '<eof>'.
          ELSE.
            str = format_string( value ).
          ENDIF.

This will be interpreted as

          IF is_eof( ) IS NOT INITIAL.

Let us assume the method IS_EOF( ) returns an object type with two constant values

          CLASS-DATA true TYPE REF TO lcl_boolean .
          CLASS-DATA false TYPE REF TO lcl_boolean.

The code should now be changed to

          IF is_eof( ) EQ true.

to be correct. The issue is that

          IF is_eof( ) .

will not trigger any error/warning from the syntax check. The code will silently fail.

Could you create a check for this case?

nomssi avatar Mar 03 '21 19:03 nomssi

yes

so, but, I do see this as a scenario for data flow analysis, that the return value of the function can take two values, and INITIAL is not one of these. Data flow analysis is difficult in ABAP, but I am starting to have some good infrastructure in https://abaplint.org so it might be possible to add there, sometime

larshp avatar Mar 04 '21 08:03 larshp