SA0130: Implicit expanding conversions

Detects implicit conversions from smaller data types to larger data types

Justification: The compiler permits any assignments of different types when the value range of the source type is completely contained within the value range of the target type. However, the compiler will build a conversion into the code as late as possible. For an assignment of type lint := dint * dint, the compiler performs the implicit conversion only after multiplication: lint := TO_LINT(dint * dint). An overflow is therefore truncated. To prevent this, you can already convert the elements: lint := TO_LINT(dint) * TO_LINT(dint). Therefore, it may be useful to report locations where the compiler implements implicit conversions in order to check whether these are exactly what is intended. Furthermore, explicit conversions can be used to improve portability to other systems when those systems have more restrictive type checks.

Importance: Low

Example

PROGRAM PLC_PRG
VAR
 byTemp : BYTE;
 usiTemp : USINT;
        uiTemp: UINT;
        iTemp : INT;
        udiTemp: UDINT;
 diTemp : DINT;
 uliTemp : ULINT;
        liTemp : LINT;
        lwTemp : LWORD;
        lrTemp : LREAL;
END_VAR

liTemp := iTemp;           // SA0130
uliTemp := usiTemp;     // SA0130
lwTemp := udiTemp;       // SA0130
lrTemp := byTemp;         // SA0130
diTemp := uiTemp;         // SA0130

byTemp.5 := FALSE;      // OK (BIT_BOOL conversion)

--> SA0130: Implizite erweiternde Konvertierung vom Typ 'INT' zu Typ 'LINT'
--> SA0130: Implizite erweiternde Konvertierung vom Typ 'USINT' zu Typ 'ULINT'
--> SA0130: Implizite erweiternde Konvertierung vom Typ 'UDINT' zu Typ 'LWORD'
--> SA0130: Implizite erweiternde Konvertierung vom Typ 'BYTE' zu Typ 'LREAL'
--> SA0130: Implizite erweiternde Konvertierung vom Typ 'UINT' zu Typ 'DINT'