P4044

Code

P4044

Message

Function block field name is already declared in a base function block via EXTENDS

This error occurs when a derived function block (one declared with EXTENDS) redeclares a field that is already declared on its base function block, or any ancestor further up the EXTENDS chain. The redeclaration is rejected even when the new field has a different type.

Inheritance in IEC 61131-3 Edition 3 gives the derived function block one set of fields — every field it inherits, plus the ones it declares — and provides no way to hold a second field of an inherited name. SUPER^ selects the base type’s implementation of an overridden method; it does not select a second field. CODESYS and TwinCAT reject the same code as a duplicate definition.

The same applies to a property: a derived function block cannot declare a field with the name of a PROPERTY it inherits.

Methods are the exception: a derived function block may declare a method with the name of one it inherits, which overrides it. So may a property with the name of one it inherits.

Example

The following code will generate error P4044:

FUNCTION_BLOCK FB_Base
VAR
    state : INT;
END_VAR
END_FUNCTION_BLOCK

FUNCTION_BLOCK FB_Derived EXTENDS FB_Base
VAR
    state : BOOL;
END_VAR
END_FUNCTION_BLOCK

To fix this error, rename the field in the derived function block (or remove it, if the inherited field already serves the purpose):

FUNCTION_BLOCK FB_Base
VAR
    state : INT;
END_VAR
END_FUNCTION_BLOCK

FUNCTION_BLOCK FB_Derived EXTENDS FB_Base
VAR
    derivedState : BOOL;
END_VAR
END_FUNCTION_BLOCK

This applies transitively: a field declared on any ancestor in the EXTENDS chain (not just the immediate base) cannot be redeclared.

A method’s own parameters and local variables are unaffected — one of those may carry the name of a field of the function block, and the method reaches the field through THIS^. See THIS and SUPER.

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.