SA0034: Enumeration variables with incorrect assignment
Function | Determines values that are assigned to an enumeration variable. Only defined enumeration constants may be assigned to an enumeration variable. |
Reason | An enumeration type variable should only have the intended values, otherwise code that uses that variable may not work correctly. We recommend using only enumerations that have the {attribute 'strict'}. In this case the compiler checks the correct use of the enumeration components. |
Importance | High |
Sample:
Enumeration E_Color:
TYPE E_Color :
(
eRed := 1,
eBlue := 2,
eGreen := 3
);
END_TYPEMAIN program:
PROGRAM MAIN
VAR
eColor : E_Color;
END_VAReColor := E_Color.eRed;
eColor := eBlue;
eColor := 1; // => SA0034