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

Feature request: "Missing initial state" error when using Self #32

Open
mx00s opened this issue Jan 18, 2022 · 1 comment
Open

Feature request: "Missing initial state" error when using Self #32

mx00s opened this issue Jan 18, 2022 · 1 comment

Comments

@mx00s
Copy link
Contributor

mx00s commented Jan 18, 2022

When I had this trait for transitions relating to my Opened state everything worked as expected with the new function making Opened the start state.

pub trait Opened {
    fn new() -> Opened;
    // ...
}

However, changing the return value for new from Opened to Self causes the macro to abort with several errors, beginning with:

error: Missing initial state. To declare an initial state you can use a function with signature like fn f() -> T where T is a declared state.

It would be nicer, I think, if I could use -> Self because it helps make the initial state stand out.

@jmg-duarte
Copy link
Contributor

Hello! Thank you for submitting this issue!

The fix should be simple enough. However, the part of the code that handles that needs a bit of refactoring.

The following function and friends should have more context on the current state:

fn extract_output_kind(&self, states: &HashSet<Ident>) -> OutputKind {
let fn_out = &self.output;
match fn_out {
ReturnType::Default => OutputKind::Unit,
ReturnType::Type(_, ty) => match **ty {
Type::Path(ref path) => {
if let Some(ident) = path.path.segments.first() {
let ident = &ident.ident;
if states.contains(ident) {
return OutputKind::State(ident.clone());
}
}
OutputKind::Other
}
_ => OutputKind::Other,
},
}
}

If the function knows which state is it part of, it can return the correct ident

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