Stream: bugs

Topic: Unhelpful err msg for return in expression position


view this post on Zulip Norbert Hajagos (Feb 27 2026 at 21:56):

Issue: #9218
I was updating the TryOperatorDesugaring example and stumbled across this error, which I could only fix, because I remembered we had talked about return only being allowed in statement positions. Playground link

main! = |_args| {
    Ok({})
}

repro = || {
    # `return` at expression position
    msg = return {}
    # the fix:
    # msg = {
    #   return {}
    # }
    msg
}

simplified_real_use_case = |input| {
    msg = match input {
        "hi" => "hi"
        _ => return "there"
        # the fix:
        # _ => {
        #   return "there"
        # }
    }
    msg
}

expect repro() == {}
expect simplified_real_use_case("hi") == "hi"

The error msg, for which I was staring, thinking "but return IS inside a function body !" :

The return keyword can only be used inside a function body.

Use `return` to exit early from a function and provide a value. For example:
    foo = |x| { if x < 0 { return Err(NegativeInput) }; Ok(x) }

Last updated: Mar 20 2026 at 12:28 UTC