Fix an assertion when handling a custom case of virtual inheritance; also reduce code duplication