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
SUPER
in a POU that doesn't extend another POU:
TheSUPER
keyword can only be used inside a POU that directly extends another POU through theEXTENDS
keyword. -
Not dereferencing
SUPER
to access members:
When accessing members of a superclass,SUPER
must be dereferenced using the^
operator:SUPER^.member
. -
Chaining
SUPER
references:
SUPER
cannot be accessed as a member of another object. Expressions likeSUPER^.SUPER^
are invalid. -
Global access position:
SUPER
cannot be used with the global access operator (.SUPER^.member
). -
Using
SUPER
with 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