Issue #2985: collect() catch after a map whose pausing lambda throws fails in rustc (NK1343), and map(sf) is not seen as failing (NK1134)

Open and answer this issue on GitHub.

bug, ready · opened 2026-11-30 · updated 2026-11-30 · 1 comment

collect() catch { .. } after a map whose pausing lambda throws passes the checker and fails in rustc. Found by run 7 of “Chains over lists, maps and std’s other producers are one loop the compiler writes” (#2927). It fails the same way on the binary at 274432a1.

Probe (nikaia run main.nika, at 13b1f3f1):

use std::time

enum Bad { Neg }

impl Error for Bad {
    fn message(ref self) -> String {
        "neg"
    }
}

fn sf(x: i64) -> i64 throws {
    time::sleep(0.millis())
    if x < 0 { throw Bad::Neg }
    return x * 2
}

fn main() throws {
    let xs: Vec[i64] = [1, 2, 3]
    let ys = xs.iter().map(fn(x) { sf(x) }).collect() catch { [] }
    println(f"{ys.len()}")
}
error[NK1343]: Internal compiler error.
    = note: Rustc output: mismatched types.
    = note: Expected struct `List<Result<i64, Thrown<Bad>>>`

Expected: 3.

With the function passed by name, map(sf), the checker instead refuses the program: NK1134: Nothing here can fail, so the catch has nothing to handle. A named function that throws and pauses is not seen as failing inside map.

To build


Generated by Claude Code

Comments

keywan-ghadami, 2026-11-30

The shape without the catch fails too, at fedd08f6 and at 3a7160c1. Found by run 9 of “Chains over lists, maps and std’s other producers are one loop the compiler writes, and seq.rs leaves Rust” (#2927).

The form is xs.iter().map(fn(x) { sf(x) }).collect(), where sf pauses and throws, inside a throws main, with no catch:

error[NK1343]: ... the `?` operator can only be applied to values that implement `Try` ... `List<Result<i64, Thrown<Bad>>>`

This is probably the same cause: the pausing loop collects List<Result<..>> where Result<List<..>, ..> is wanted. The fix for this issue should cover both forms, with a test for each.


Generated by Claude Code

Back to Open Issues