SA0034: Enumerations with incorrect assignmentPermalink

Detects values that are assigned to an enumeration variable. Only defined enumeration constants of an enumeration variable are permitted to be assigned.

Justification: A variable of the enumeration type should have only the intended values, otherwise the code that uses this variable may not work correctly. We recommend to always use enumerations with the ‎{attribute 'strict'}‎. Then the compiler already checks the correct use of the enumeration components.

Importance: High

Example

TYPE COLOR :
(
	Red := 0,
	Green,
	Yellow
);
END_TYPE

PROGRAM PLC_PRG
VAR
	eColor1: COLOR;
END_VAR

eColor1 := COLOR.Red;
eColor1 := 1;         // SA0034

--> SA0034: Use enumeration value instead of 'INT#1'