Skip to content

Enum types are not topologically sorted #275

@Bushuo

Description

@Bushuo

First of all, thank you for this great crate. I use it a lot in my project (for which I made a fork and implemented rescript support, probably not complete).
In rescript all types inside a module need to be topologically sorted by dependency.

I expanded on the snapshot test orders_types with the following.
Purposefully named such that BEnum should be declared before AEnum after sorting.

#[typeshare]
#[serde(rename_all = "camelCase", tag = "type", content = "data")]
pub enum AEnum {
    Variant1(BEnum),
    Variant2(f32),
}

#[typeshare]
#[serde(rename_all = "camelCase")]
pub enum BEnum {
    Var1,
    Var2,
}

Expected

type bEnum =     | @as("var1") var1      | @as("var2") var2

@tag("type")
type aEnum =
         | @as("variant1") variant1({data: bEnum})
         | @as("variant2") variant2({data: float})

Actual

@tag("type")
type aEnum =
         | @as("variant1") variant1({data: bEnum})
         | @as("variant2") variant2({data: float})

type bEnum =     | @as("var1") var1      | @as("var2") var2

If I reverse the names of the types the output is correct. So I guess they are sorted alphabetically beforehand.
I guess kotlin is also terse with enum output so you could verify there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions