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

Error when using non-C like enums inside a #[typestate] block #25

Open
jquesada2016 opened this issue Dec 13, 2021 · 2 comments
Open

Error when using non-C like enums inside a #[typestate] block #25

jquesada2016 opened this issue Dec 13, 2021 · 2 comments

Comments

@jquesada2016
Copy link

I ran across three related issues when reproducing this issue.

Take the following:

#[typestate]
mod my_state {
    #[automaton]
    struct Aut;

    #[state]
    struct State1(HelperEnum);

    trait State1 {
        fn new() -> State1;

        fn done(self);
    }

    enum HelperEnum {}
}

The above produces the following error:

Unused transitions are not allowed.

After this, I tried changing the enum to be:

enum HelperEnum {
      Variant1,
      Variant2,
}

And got:

`enum` variant is not a declared state.

And finally, once I got to what I was trying to do (algebraic enums), by doing the following:

enum HelperEnum {
        Variant1 { helper_state: bool },
        Variant2,
    }
}

I got the following error:

Only unit (C-like) `enum` variants are supported.

My current workaround is to declare the HelperEnum just outside the module and use it from there. This makes code a bit disjoint, but it's doable. If this is intended behavior, it might be a good idea to add a note to the docs about it :)

@jquesada2016
Copy link
Author

I forgot to mention, but the reason I think this might be intentional behavior is because it appears to be an internal mechanism for keeping track of transitions or generating the graphs, but that's just my guess.

@jmg-duarte
Copy link
Contributor

Sorry for the (very) late reply. "Normal" enumerations are disallowed inside the module as regular enumerations are used for decision-states. Support for them could be added through the usage of #[state] but I don't know if that won't bring more complexity to the existing codebase for little benefit

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