Fixed several problems related to @extend directive (Ticket #10976)

Change-Id: I5e409856601aa514965319453c11946028b08dda