Stream: bugs

Topic: Issue with Closures on map_ok and map_err


view this post on Zulip Edwin Santos (Dec 03 2025 at 18:11):

Hi, I just rebuilt the compiler from source and while trying to implement map_ok and map_err I'm getting an error on the following:

main! = |args| {
    identity = |a| a
    swap_errs = |_| Exit(101)
    init_try : Try(U32, [SomeError, ..others])
    init_try = Ok(30) #Try.Err(SomeError)
    final_try1 = map_err(init_try, swap_errs)
    final_try2 = map_ok(init_try, identity)

    Ok({})

}

map_ok : Try(a, err), (a -> b) -> Try(b, err)
map_ok = |try, fn| {
    match try {
        Ok(ok_val) => Ok(fn(ok_val))
        Err(e) => Err(e)
    }
}

map_err : Try(a, err_1), (err_1 -> err_2) -> Try(a, err_2)
map_err = |try, err_fn| {
    match try {
        Ok(ok) => Ok(ok)
        Err(e) => Err(err_fn(e))
    }
}

Yields the following panicking stack trace:

thread 3865772 panic: trying to add var at rank 2, but current rank is 1
???:?:?: 0x106346793 in _generalize.VarPool.addVarToRank (???)
???:?:?: 0x10635031b in _Check.unifyWithCtx (???)
???:?:?: 0x10620805b in _Check.unify (???)
???:?:?: 0x10634963b in _Check.generateAnnoTypeInPlace (???)
???:?:?: 0x10634979f in _Check.generateAnnoTypeInPlace (???)
???:?:?: 0x10634af8b in _Check.generateAnnotationType (???)
???:?:?: 0x1061fc7fb in _Check.checkDef (???)
???:?:?: 0x106202aa3 in _Check.checkExpr (???)
???:?:?: 0x106204893 in _Check.checkExpr (???)
???:?:?: 0x10634e0cb in _Check.checkBlockStatements (???)
???:?:?: 0x1061fd577 in _Check.checkExpr (???)
???:?:?: 0x1062041db in _Check.checkExpr (???)
???:?:?: 0x1061fd5e7 in _Check.checkExpr (???)
???:?:?: 0x1061fc82b in _Check.checkDef (???)
???:?:?: 0x10601fa8b in _Check.checkFile (???)
???:?:?: 0x10602844f in _main.setupSharedMemoryWithModuleEnv (???)
???:?:?: 0x10602f9f7 in _main.rocRun (???)
???:?:?: 0x106184773 in _main.mainArgs (???)
???:?:?: 0x106185bf3 in _main.main (???)
???:?:?: 0x1061860fb in _main (???)
???:?:?: 0x191628273 in ??? (???)
???:?:?: 0x0 in ??? (???)
zsh: abort      roc aoc_2025_01.roc

map_err or map_ok will panic in isolation, also tried with both an Ok as the original value and the commented out Err. All combinations result in this stack trace.


Last updated: Dec 21 2025 at 12:15 UTC