P4001

Code

P4001

Message

Function call mixes named (formal) and positional (non-format) input arguments

This error occurs when a function call or a function block invocation mixes named (formal) and positional (non-formal) input arguments. A call is either formal, naming every argument, or non-formal, giving the arguments in declaration order.

Example

The following code will generate error P4001:

FUNCTION_BLOCK Callee
VAR_INPUT
    Input1: BOOL;
    Input2: BOOL;
END_VAR
END_FUNCTION_BLOCK

FUNCTION_BLOCK Caller
VAR
    FbInstance : Callee;
END_VAR
FbInstance(Input1 := TRUE, FALSE);  (* Error: Mixed formal and non-formal arguments *)
END_FUNCTION_BLOCK

The function block invocation mixes named input Input1 := TRUE with positional input FALSE, which is not allowed.

To fix this error, use either all named or all positional arguments:

FUNCTION_BLOCK Callee
VAR_INPUT
    Input1: BOOL;
    Input2: BOOL;
END_VAR
END_FUNCTION_BLOCK

FUNCTION_BLOCK Caller
VAR
    FbInstance : Callee;
END_VAR
FbInstance(Input1 := TRUE, Input2 := FALSE);  (* Correct: All named arguments *)
END_FUNCTION_BLOCK

The same applies to a function call:

FUNCTION Diff : INT
VAR_INPUT
    A : INT;
    B : INT;
END_VAR
    Diff := A - B;
END_FUNCTION

PROGRAM main
VAR
    x : INT;
END_VAR
    x := Diff(1, B := 2);      (* Error: Mixed formal and non-formal arguments *)
    x := Diff(A := 1, B := 2); (* Correct: All named arguments *)
    x := Diff(1, 2);           (* Correct: All positional arguments *)
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.