P4023

Code

P4023

Message

Function call has named argument that does not match any declared input parameter

This error occurs when a function call uses a named argument that does not match any declared input parameter of the function.

Example

The following code will generate error P4023:

FUNCTION MY_ADD : INT
VAR_INPUT
    A : INT;
    B : INT;
END_VAR
    MY_ADD := A + B;
END_FUNCTION

PROGRAM main
VAR
    result : INT;
END_VAR
    result := MY_ADD(X := 1, B := 2);  (* Error: 'X' is not a declared parameter *)
END_PROGRAM

The named argument X does not match any input parameter of MY_ADD, which declares A and B.

To fix this error, use a parameter name that matches one of the function’s declared input parameters:

FUNCTION MY_ADD : INT
VAR_INPUT
    A : INT;
    B : INT;
END_VAR
    MY_ADD := A + B;
END_FUNCTION

PROGRAM main
VAR
    result : INT;
END_VAR
    result := MY_ADD(A := 1, B := 2);  (* Correct: Both names match declared parameters *)
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.