SA0168: Unnecessary Assignments Permalink

Detects assignments to variables which do not have any effect in the code.

Justification: When values are assigned to a variable multiple times without the variable being evaluated between assignments, the first assignments do not have any effect on the program.

Importance: Low

Example

PROGRAM PLC_PRG
VAR
	dwVal1 : DWORD;
	dwVal2 : DWORD;
END_VAR


dwVal1 := 1;				// unnecessary assignment
IF  dwVal2 > 100 THEN
	dwVal2 := 0;
	dwVal2 := dwVal2 + 1;
END_IF
dwVal1 := 2; 

--> SA0168: The variable 'dwVal1' is assigned but its value is never used.