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

Cannot chain Ok in expression containing try operator #7080

Open
ageron opened this issue Sep 15, 2024 · 0 comments
Open

Cannot chain Ok in expression containing try operator #7080

ageron opened this issue Sep 15, 2024 · 0 comments

Comments

@ageron
Copy link
Contributor

ageron commented Sep 15, 2024

This code fails using roc nightly pre-release, built from commit 9a4d556 on Mon Sep 9 09:02:33 UTC 2024:

app [main] {
    pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.15.0/SlwdbJ-3GR7uBWQo6zlmYWNYOxnvo8r6YABXD-45UOw.tar.br",
}

import pf.Stdout

inc = \i ->
    if i > 2 then
        Err MaxReached
    else
        Ok (i + 1)

run = \i ->
    i
    |> inc?
    |> inc?
    |> Ok

main =
    result = run 0
    Stdout.line! "Result: $(result |> Inspect.toStr)"

The error is:

An internal compiler expectation was broken.
This is definitely a compiler bug.
Please file an issue here: <https://github.com/roc-lang/roc/issues/new/choose>
a Expr::TrySuffix expression was not completely removed in desugar_value_def_suffixed
Location: crates/compiler/can/src/expr.rs:1125:40

The problem disappears if I use an intermediate variable:

run = \i ->
    newi =
        i
        |> inc?
        |> inc?
    Ok newi

Alternatively, the problem also disappears if I stop using the try operator:

inc2 = \i ->
    i + 1

run = \i ->
    i
    |> inc2
    |> inc2
    |> Ok

So there seems to be something fishy with the combination of |> Ok and the ? operator.

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