Invalid use of the SUPER keyword
The SUPER keyword provides access to members of a parent POU (Program Organization Unit) in an inheritance hierarchy. However, there are several rules governing its proper use:
Common errors
-
Using
SUPERin a POU that doesn't extend another POU:
TheSUPERkeyword can only be used inside a POU that directly extends another POU through theEXTENDSkeyword. -
Not dereferencing
SUPERto access members:
When accessing members of a superclass,SUPERmust be dereferenced using the^operator:SUPER^.member. -
Chaining
SUPERreferences:
SUPERcannot be accessed as a member of another object. Expressions likeSUPER^.SUPER^are invalid. -
Global access position:
SUPERcannot be used with the global access operator (.SUPER^.member). -
Using
SUPERwith type cast operators:
The type cast operator (<type>#) cannot be used withSUPER.
Examples of invalid use
// Error: Using SUPER in a POU that doesn't extend another POU
FUNCTION_BLOCK fb
SUPER^.x := 2; // Error: Invalid use of `SUPER`
END_FUNCTION_BLOCK
// Error: Not dereferencing SUPER when accessing members
FUNCTION_BLOCK child EXTENDS parent
SUPER.x := 20; // Error: `SUPER` must be dereferenced to access its members
END_FUNCTION_BLOCK
// Error: Chaining SUPER references/SUPER in member access
FUNCTION_BLOCK child EXTENDS parent
x.SUPER^.y := 20;
SUPER^.SUPER^.x := 20;
// Error: `SUPER` is not allowed in member-access position
END_FUNCTION_BLOCK
// Error: Global access position
FUNCTION_BLOCK child EXTENDS parent
.SUPER^.x := 20; // Error: `SUPER` is not allowed in global-access position
END_FUNCTION_BLOCK
// Error: Using SUPER with type cast
FUNCTION_BLOCK child EXTENDS parent
p := parent#SUPER; // Error: The `<type>#` operator cannot be used with `SUPER`
END_FUNCTION_BLOCK