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

missing expression return #7545

Open
Anton-4 opened this issue Jan 24, 2025 · 2 comments
Open

missing expression return #7545

Anton-4 opened this issue Jan 24, 2025 · 2 comments

Comments

@Anton-4
Copy link
Collaborator

Anton-4 commented Jan 24, 2025

── MISSING EXPRESSION in ./examples/DesugaringTry/main.roc ─────────────────────

I am partway through parsing a when expression, but I got stuck here:

21│      when Str.split_first(str, " was born in ") is
22│          Err(err1) -> return Err(err)
                          ^

I was expecting to see an expression like 42 or "hello".
app [main!] { cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/bi5zubJ-_Hva9vxxPq4kNx4WHX6oFs8OP6Ad0tCYlrY.tar.br" }

import cli.Stdout

main! = |_args|
    Stdout.line!(Inspect.to_str(parse_name_and_year("Alice was born in 1990")))?
    Stdout.line!(Inspect.to_str(parse_name_and_year_try("Alice was born in 1990")))?

    Ok({})

### start snippet question
parse_name_and_year : Str -> Result { name : Str, birth_year : U16 } _
parse_name_and_year = |str|
    { before: name, after: birth_year_str } = Str.split_first(str, " was born in ")?
    birth_year = Str.to_u16(birth_year_str)?
    Ok({ name, birth_year })
### end snippet question

parse_name_and_year_try = |str|
    ### start snippet try
    when Str.split_first(str, " was born in ") is
        Err(err1) -> return Err(err)
        Ok({ before: name, after: birth_year_str }) ->
            when Str.to_u16(birth_year_str)? is
                Err(err2) -> return Err(err2)
                Ok(birth_year) ->
                    Ok({ name, birth_year })
### end snippet try

expect parse_name_and_year("Alice was born in 1990") == Ok({ name: "Alice", birth_year: 1990 })
expect parse_name_and_year_try("Alice was born in 1990") == Ok({ name: "Alice", birth_year: 1990 })
@Anton-4
Copy link
Collaborator Author

Anton-4 commented Jan 24, 2025

Workaround is to move the return to its own line.

@Anton-4
Copy link
Collaborator Author

Anton-4 commented Jan 24, 2025

zulip discussion

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

1 participant