P4062

Code

P4062

Message

Function block qualifier requires choosing a dialect or –allow-fb-inheritance flag

This error occurs when a function block declaration carries a qualifier (PUBLIC, PRIVATE, PROTECTED, INTERNAL, FINAL, OVERRIDE or ABSTRACT) between FUNCTION_BLOCK and the name, without the --allow-fb-inheritance compiler flag.

The qualifiers are part of the object-oriented extension that IEC 61131-3:2013 (Edition 3), CODESYS and TwinCAT add to function blocks. The Edition 2 grammar has no qualifiers on a function block.

Example

The following code will generate error P4062:

FUNCTION_BLOCK PUBLIC FINAL FB_Motor
VAR
    speed : INT;
END_VAR
END_FUNCTION_BLOCK

To fix this error, remove the qualifiers:

FUNCTION_BLOCK FB_Motor
VAR
    speed : INT;
END_VAR
END_FUNCTION_BLOCK

IronPLC does not enforce access specifiers or FINAL, so removing them does not change what the program does.

Or enable the extension:

Pass the --allow-fb-inheritance flag to enable it, or select a dialect that includes it. See Enabling Dialects and Features for the dialects and flags reference.

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.