P4057¶
- Code
P4057
- Message
Method has no return value and cannot be used in an expression
This error occurs when a method that has no return type is called in an
expression, for example on the right side of an assignment or in an IF
condition. Such a method produces no value, so there is nothing for the
expression to use. This is part of IEC 61131-3 Edition 3’s OOP extension.
Example¶
The following code will generate error P4057:
FUNCTION_BLOCK FB_Motor
VAR
bRunning : BOOL;
END_VAR
METHOD Start
bRunning := TRUE;
END_METHOD
END_FUNCTION_BLOCK
PROGRAM main
VAR
m : FB_Motor;
started : BOOL;
END_VAR
started := m.Start();
END_PROGRAM
To fix this error, either call the method as a statement, or give the method a return type and assign it in the method body:
FUNCTION_BLOCK FB_Motor
VAR
bRunning : BOOL;
END_VAR
METHOD Start : BOOL
bRunning := TRUE;
Start := bRunning;
END_METHOD
END_FUNCTION_BLOCK
PROGRAM main
VAR
m : FB_Motor;
started : BOOL;
END_VAR
started := m.Start();
END_PROGRAM
Think IronPLC is wrong about this?
If you believe this diagnostic is incorrect, open an issue on GitHub with a small sample that demonstrates the problem.