SA0095: Assignments in conditions
Detects assignments in conditions of IF, CASE, or REPEAT constructs
Justification: An assignment (:=) and a comparison (=) can easily be mistaken. As a result, an assignment in a condition can easily be unintentional, and it is therefore reported. This can also confuse the reader of the code.
Importance: High
Example 88. Example
PROGRAM PLC_PRG
VAR
iCond1:INT := INT#1;
iCond2:INT := INT#2;
xCond:BOOL := FALSE;
iVar : INT;
END_VARIF INT_TO_BOOL(iCond1 := iCond2) THEN // SA0095
iCond1 := INT#1;
iCond2 := INT#2;
ELSIF (iCond1 := 11) = 11 THEN // SA0095
iCond1 := INT#1;
iCond2 := INT#2;
END_IF
IF xCond := TRUE THEN // SA0095
xCond := FALSE;
END_IF
IF (xCond := FALSE) OR (iCond1 := iCond2) = 12 THEN // SA0095
xCond := FALSE;
iCond1 := INT#1;
iCond2 := INT#2;
END_IF
IF (iVar := iVar + 1) = 120 THEN // SA0095 (can be valid, but is not reparable very well
iVar := 0;
END_IF
WHILE (xCond = TRUE) OR (iCond1 := iCond2) = 12 DO // SA0095
xCond := FALSE;
END_WHILE
//Error: assignment in repeat loop
REPEAT
xCond := FALSE;
UNTIL (xCond = TRUE) OR (iCond1 := iCond2) = 12 // SA0095
END_REPEAT Output in the Messages view:
SA0095: Assignment in condition: '...'