Attention
IronPLC implements many parts of the IEC 61131-3 standard and is working toward full Structured Text support. Key features still missing include arrays and structures. Try it out in the IronPLC Playground.
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 requires exact type matching for function return values.
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));