Fix array length checks while writing
After the introduction of direct serialization, the tests for
array length checks were failing in the direct serialization
case. Fix that.
Also (re)introduce tests for the indirect serialization case
(i.e. inside a variant), which still pass.