Open farmaazon opened 1 year ago
I dived into the code and seemingly the problem is that we lose information about actual variant index around here: https://github.com/serde-rs/serde/blob/360606b9a63ba4e594dc20ddf0e20228b60b34cb/serde_derive/src/de.rs#L1217
Here the enumerate is properly called before filter, but the index is used only to construct fieldX
identifier.
Then in https://github.com/serde-rs/serde/blob/360606b9a63ba4e594dc20ddf0e20228b60b34cb/serde_derive/src/de.rs#L1339 the fields are enumerated again, this time without the skipped variant.
I could create a PR fixing this, but I'm not sure what is the policy about such breaking changes?
When running tests on this snippet:
both of them fail, because
deserialized
is a variant D.This seems to be a
serde_derive
problem: when expanding macro, the serialization the value index of C variant is 2:While the FieldVisitor in derived Deserialize expects C being represented by 1u64 if I read code correctly:
And indeed, when I implement Deserialize by hand changing only those values, the tests pass.
I'd expect that when both Serialize and Deserialize are derived, then serializing and then deserializing a value always gives same value, regardless of the data format.