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

enum aliases support is broken #105

Closed
pompon0 opened this issue Aug 29, 2023 · 1 comment
Closed

enum aliases support is broken #105

pompon0 opened this issue Aug 29, 2023 · 1 comment

Comments

@pompon0
Copy link

pompon0 commented Aug 29, 2023

For example for:

enum AliasedEnum {
    option allow_alias = true;

    ALIAS_FOO = 0;
    ALIAS_BAR = 1;
    ALIAS_BAZ = 2;
    MOO = 2;
    moo = 2;
    bAz = 2;
}

pbjson_build generates:

impl serde::Serialize for AliasedEnum {
    #[allow(deprecated)]
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        let variant = match self {
            Self::AliasFoo => "ALIAS_FOO",
            Self::AliasBar => "ALIAS_BAR",
            Self::AliasBaz => "ALIAS_BAZ",
            Self::Moo => "MOO",
            Self::Moo => "moo",
            Self::BAz => "bAz",
        };
        serializer.serialize_str(variant)
    }
}

while prost-build generates:

    #[repr(i32)]
    pub enum AliasedEnum {
        AliasFoo = 0,
        AliasBar = 1,
        AliasBaz = 2,
    }

i.e. pbjson_build incorrectly assumes that there are no aliases and thinks that each alias has its own rust enum variant.

@tustvold
Copy link
Contributor

Closed by #103

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

No branches or pull requests

2 participants