This relies on the fact that derived class (OwnedValueAccessor) and based class (SlotAccessor) have offset of 0:
https://github.com/10gen/mongo/blob/master/src/mongo/db/exec/sbe/vm/vm.cpp#L553
While this is usually true, it is a compiled-dependent behavior, see:
https://en.cppreference.com/w/cpp/language/derived_class
Each direct and indirect base class is present, as base class subobject, within the object representation of the derived class at an ABI-dependent offset. Empty base classes usually do not increase the size of the derived object due to empty base optimization. The constructors of base class subobjects are called by the constructor of the derived class: arguments may be provided to those constructors in the member initializer list.
We should downcast to proper that derived class before writing the pointer to code fragment.