SA0095: Zuweisung in Bedingung
Funktion | Ermittelt Zuweisungen in Bedingungen von IF-, CASE-, WHILE- oder REPEAT-Konstrukten. |
Begründung | Ein Zuweisung (:=) und ein Vergleich (=) kann leicht verwechselt werden. Eine Zuweisung in einer Bedingung kann daher leicht unabsichtlich erfolgt sein und wird deswegen gemeldet. Auch der Leser des Codes kann dadurch verwirrt werden. |
Wichtigkeit | Hoch |
Beispiele:
PROGRAM MAIN
VAR
bTest : BOOL;
bResult : BOOL;
bValue : BOOL;
b1 : BOOL;
n1 : INT;
n2 : INT;
nCond1 : INT := INT#1;
nCond2 : INT := INT#2;
bCond : BOOL := FALSE;
nVar : INT;
eSample : E_Sample;
END_VAR// IF constructs
IF (bTest := TRUE) THEN // => SA0095
DoSomething();
END_IF
IF (bResult := F_Sample(bInput := bValue)) THEN // => SA0095
DoSomething();
END_IF
b1 := ((n1 := n2) = 99); // => SA0095
IF INT_TO_BOOL(nCond1 := nCond2) THEN // => SA0095
DoSomething();
ELSIF (nCond1 := 11) = 11 THEN // => SA0095
DoSomething();
END_IF
IF bCond := TRUE THEN // => SA0095
DoSomething();
END_IF
IF (bCond := FALSE) OR (nCond1 := nCond2) = 12 THEN // => SA0095
DoSomething();
END_IF
IF (nVar := nVar + 1) = 120 THEN // => SA0095
DoSomething();
END_IF
// CASE construct
CASE (eSample := E_Sample.eMember0) OF // => SA0095
E_Sample.eMember0:
DoSomething();
E_Sample.eMember1:
DoSomething();
END_CASE
// WHILE construct
WHILE (bCond = TRUE) OR (nCond1 := nCond2) = 12 DO // => SA0095
DoSomething();
END_WHILE
// REPEAT construct
REPEAT
DoSomething();
UNTIL
(bCond = TRUE) OR ((nCond1 := nCond2) = 12) // => SA0095
END_REPEAT