Attention
IronPLC supports IEC 61131-3 Structured Text excluding I/O mapping.
P4027¶
- Code
P4027
- Message
Function return type does not match assignment destination type
This error occurs when a function’s return type does not match the type of the variable
being assigned to. IronPLC allows implicit widening between integer types (for example,
a function returning SINT assigned to a DINT variable), but rejects other type
mismatches such as real to integer or narrowing conversions.
For the full set of allowed implicit conversions, see Type Conversions.
Example¶
The following code will generate error P4027:
FUNCTION GET_VALUE : REAL
VAR_INPUT
A : REAL;
END_VAR
GET_VALUE := A;
END_FUNCTION
PROGRAM main
VAR
result : INT;
x : REAL;
END_VAR
result := GET_VALUE(x); (* Error: REAL return assigned to INT variable *)
END_PROGRAM
The function GET_VALUE returns REAL, but result is INT.
To fix this error, use an explicit type conversion:
result := REAL_TO_INT(GET_VALUE(x));