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

Compiler crash on a certain use (possibly incorrect) of ? syntax sugar #7177

Open
sylbru opened this issue Oct 21, 2024 · 1 comment
Open
Labels
bug Something isn't working P-medium Medium priority/frequency

Comments

@sylbru
Copy link

sylbru commented Oct 21, 2024

As the compiler says it’s definitely a compiler bug… here’s a report:

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:1122:40

This is the code that triggered this:

latestCommitTimestampFromLog : Str -> Result I128 [InvalidNumStr, NotFound]
latestCommitTimestampFromLog = \logOutput ->
    logOutput
        |> Str.splitFirst? "\n"
        |> \{ before: entry } -> Str.splitFirst? entry " "
        |> \{ after: isoTimestamp } -> Str.toI128 isoTimestamp
        |> Result.map \timestampSeconds -> 1000 * timestampSeconds

In my editor the first three lines of the body are highlighted with a curvy underline in red, but I’m not sure if that’s significant.

@sylbru
Copy link
Author

sylbru commented Oct 22, 2024

I should also mention that I was in the process of converting my function from Result.try to ?, so below is the last working version before I attempt to migrate the second Str.splitFirst call to ?. (you might tell me if I’m doing something wrong there)

latestCommitTimestampFromLog : Str -> Result I128 [InvalidNumStr, NotFound]
latestCommitTimestampFromLog = \logOutput ->
    logOutput
        |> Str.splitFirst? "\n"
        |> \{ before: entry } -> Str.splitFirst entry " "
        |> Result.try \{ after: isoTimestamp } -> Str.toI128 isoTimestamp
        |> Result.map \timestampSeconds -> 1000 * timestampSeconds

Aaaand I should add that I now have a better understanding of how to use ?:

latestCommitTimestampFromLog : Str -> Result Utc [InvalidNumStr, NotFound]
latestCommitTimestampFromLog = \logOutput ->
    { before: entry } = logOutput |> Str.splitFirst? "\n"
    { after: timestamp } = Str.splitFirst? entry " "
    Str.toI128 timestamp
    |> Result.map \timestampSeconds -> Utc.fromMillisSinceEpoch (1000 * timestampSeconds)

@Anton-4 Anton-4 added bug Something isn't working P-medium Medium priority/frequency labels Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P-medium Medium priority/frequency
Projects
None yet
Development

No branches or pull requests

2 participants