SA0106: Virtual method calls in FB_INITPermalink

Detects method calls in the ‎FB_Init‎ method of a base function block, which are overwritten by a function block derived from a base function block

Justification: In these cases, it could be that the variables in the overwritten methods are not initialized in the base FB.

Importance: High

Example

The function block ‎FB_A‎ includes the methods ‎FB_Init‎ and ‎Meth_MyInit‎. ‎FB_Init‎ calls ‎Meth_MyInit‎ for initialization. The function block ‎FB_B‎ is derived from ‎FB_A‎. ‎PLC_PRG‎ calls ‎FB_B‎ and therefore uses its ‎mbMyDintB‎ variable before it has been initialized. ‎FB_B.Meth_MyInit‎ overwrites ‎FB_A.Meth_MyInit‎.

FUNCTION_BLOCK FB_A
VAR
	mbMyDintA : DINT;	
END_VAR FUNCTION_BLOCK FB_B EXTENDS FB_A
VAR
	mbMyDintB : DINT;
END_VAR METHOD FB_Init : BOOL
VAR_INPUT
	bInitRetains:BOOL;
	bInCopyCode:BOOL;
END_VAR
VAR
	diDummy:DINT;			// SA0106
END_VAR
mbMyDintA := 123;
diDummy := Meth_MyInit(); METHOD Meth_MyInit : DINT
VAR_INPUT
END_VAR
mbMyDintB := 123; // access to member of FB_B PROGRAM PLC_PRG
VAR
	g_BInst : FB_B;
 xVar : BOOL;
END_VAR
xVar := g_BInst.fb_init(TRUE, TRUE);
//this instruction causes the following order of initializations:
//FB_A.fb_init
//FB_B.Meth_MyInit // SA0106
//FB_B.fb_init
//FB_B.Meth_MyInit

--> SA0106: Virtual method call 'Meth_MyInit' in FB_INIT