[Joanju Logo]
    If Indent Joanju Software

 Home


 Products
      Proparse
      Analyst


 Prices/Licenses
 Purchase
 Services
 Support
 Forum


 White Papers Etc.


 Projects, Utils,
 and Contributors



 Site History
 Contact us
 About Joanju
 Privacy
Rule "ifindent"

    This rule in Prolint finds subtle bugs in IF statement logic.

    It works by examining IF statements, comparing the developer's indentation of the code (and therefore, probable intentions) with how the Progress compiler will understand the code. When the indentation doesn't agree with how the code really works, the rule will generate a warning.

Two interesting examples of bugs found by this rule in production code:

  1. ELSE paired to the wrong IF. (paraphrased code; caps and indenting unchanged):

    
     if var1 = "" OR var1 = "A" then next BIGBLOCK.
     else if var1 = "B" or
             var1 = "C" then next BIGBLOCK.
     else if (var2 <> var3) THEN
              IF var4 <> "X" then next BIGBLOCK.   /* 1 */ 
     else do:                                      /* 2 */ 
        /* lots of other important stuff */
     end.
    

    The "else do" (2) actually belongs to the "IF var4..." (1), so the entire "else do" is rarely being executed. Oops. (The "else do" is controlled by the "IF var4" but is outdented from it).


  2. Missing DO: ... END. (paraphrased):

    
     &scop OPEN-QUERY-1 OPEN QUERY Q1 FOR EACH customer NO-LOCK.
     &scop OPEN-QUERY-2 OPEN QUERY Q2 FOR EACH order NO-LOCK.
     &scop OPEN-BROWSERS-IN-QUERY-F-Main {&OPEN-QUERY-1} {&OPEN-QUERY-2}
    
     IF cond THEN DO:
       /* Some stuff */
     END.
     ELSE
       {&OPEN-BROWSERS-IN-QUERY-F-Main}
    

    Only the first query in "&OPEN-BROWSERS-IN-QUERY-F-Main" is actually conditional; the second query will always get opened. (The "OPEN QUERY Q2" is not controlled by the "ELSE", but it is indented from it as if it were - which you can see if you do a COMPILE... PREPROCESS).