roc
roc copied to clipboard
Compiler crash on a certain use (possibly incorrect) of `?` syntax sugar
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.
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)