Skip to content

wrong type mismatch when using ? #8646

Description

@Anton-4
app [main!] { pf: platform "./platform/main.roc" }

import pf.Stdout

main! = || {
    # fails
    #Stdout.line!(Str.inspect(question_fail(["1", "not a number", "100"])))

    # works
    Stdout.line!(Str.inspect(this_works(["1", "not a number", "100"])))
}

# question_fail : List(Str) -> Try(Str, _)
# question_fail = |strings| {
#     first_str = strings.first()?

#     Ok(first_str)
# }

this_works : List(Str) -> Try(Str, _)
this_works = |strings| {
    first_str_res = strings.first()

    first_str_res
}

Uncommenting yields:

❯ ./zig-out/bin/roc test/fx/hello_world.roc --no-cache
-- TYPE MISMATCH ---------------------------------

This expression is used in an unexpected way:
   ┌─ test/fx/hello_world.roc:15:17
   │
15 │     first_str = strings.first()?
   │                 ^^^^^^^

It has the type:
    List(Str)

But I expected it to be:
    { unknown: _field }

Found 1 error(s) and 0 warning(s) for test/fx/hello_world.roc.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions