Weird incompatible match arm problem

I have the following code:

match arg {
                Num(x) => Ok(forth.stack.push(*x)),
                Dup => Arg::dup(forth.stack),
                Drop => Arg::drop(forth.stack),
                Swap => Arg::swap(forth.stack),
                Over => Arg::over(forth.stack),
                Oper(operator) => match operator {
                    Plus => Arg::plus(forth.stack),
                    Subt => Arg::subt(forth.stack),
                    Mult => Arg::mult(forth.stack),
                    Divd => Arg::divd(forth.stack),
                SemiColon => Ok(()),
                Cmd(strng) => Ok(()),
                Colon => {
                    let mut v = vec![];
                    while let Some(nxt) = {
                        if nxt != &SemiColon {
                        } else {

This gives me the error mismatched types: expected (), found enumstd::result::Result``. If I remove the Ok(()) near the end, I get match arms have incompatible types: expected enumstd::result::Result, found () for the last match. It's a catch-22. How do I fix this?

Not sure if related, but clippy also is weird about this match because I can't have the Colon arm anywhere but the final position as clippy (or I guess ALE using clippy) removes the comma after the braces.

I can see at least two different types coming from the match. In Num(x) => ... you are returning a Result but in Dup => ... you are returning an Arg. You need to unify the return type of the match arg { ... } expression.

1 Like

No, sorry I didn't post the full code, but the Arg::dup(forth.stack) is a function call that returns a Result.


are u returning this from a function, that has () as it's return type?

1 Like

No, the entire function returns a Result.