Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with round tripping untagged unions. #530

Closed
Eh2406 opened this issue Mar 15, 2024 · 3 comments · Fixed by #531
Closed

Problems with round tripping untagged unions. #530

Eh2406 opened this issue Mar 15, 2024 · 3 comments · Fixed by #531

Comments

@Eh2406
Copy link

Eh2406 commented Mar 15, 2024

I was trying to debug a mysterious issue while investigating a bug. My implementations of serialize and deserialize were complicated but look like they should match. After extensive investigation I discovered that if I used serde_json they did match, but when I used ron they did not. I was able to reduce the input to this playground which uses serde_json and passes. Unfortunately ron is not available on playground, but this test fails running locally:

    #[test]
    fn serde_test() {
        #[derive(serde::Deserialize, serde::Serialize, PartialEq, Eq, Debug)]
        #[serde(untagged)]
        enum EitherInterval<V> {
            B(Interval<V>),
            D(V, Option<V>),
        }

        type Interval<V> = (Bound<V>, Bound<V>);

        let t = EitherInterval::B((Excluded(0u8), Unbounded));
        let s = ron::ser::to_string(&t).unwrap();
        let r = ron::de::from_str(&s).unwrap();
        assert_eq!(t, r);
    }

Is this a bug? Is there a known workaround?

juntyr added a commit to juntyr/ron that referenced this issue Mar 16, 2024
@juntyr
Copy link
Member

juntyr commented Mar 16, 2024

Thanks for reaching out, @Eh2406. On the last version, it seems that this is now working. Could you try your code with version ron = "=0.9.0-alpha.0" (the prerelease for v0.9) and see if it works? If v0.9 does indeed fix the issue, I'll merge your testcase into our testsuite in #531 to ensure it continues working in the future :)

@Eh2406
Copy link
Author

Eh2406 commented Mar 16, 2024

Thank you for the fast response. I will give it a try as soon as I have a chance. I have a larger test case set up on my work computer, so may not get to it until Monday.

@Eh2406
Copy link
Author

Eh2406 commented Mar 17, 2024

Yes the larger case also passed with 0.9. Sorry I didn't check the change log for unreleased changes. Sounds like it was fixed in #451.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants