This fix still leaves inherited fields from base classes unpopulated
(even if they are accessed in the code), and might cause false
positives, but fix crashes that could happen because of source /
destination mismatches.
More details:
When a struct is declared, the Record value of the struct is usually
initialized with Environment::createValue() which internally calls
getObjectFields() (via filtering in DACtx::getModeledFields())
to collects all fields from the current and base classes.
However, if a struct is initialized with InitListExpr, its fields are
initialized based on what is returned by getFieldsForInitListExpr(),
which doesn't collect fields from base classes. Moreover, if the base
classes have their own InitListExpr, those InitListExpr's are also
visited, but the field values and locations that are initialized by
them are not merged when the child class's InitListExpr is visited.
This change adds a new getChildOrError() method in StorageLocation
and uses it in copyRecord(), so that only the fields that exist in
both record can be copied. A follow-up change can add more proper fix
around InitListExpr.