Issue #1098: Over iter() of a copy list, a named function into map and a filter_map lambda with if/null pass check and fail in rustc (&i64)

Open and answer this issue on GitHub.

ready · opened 2026-10-31 · updated 2026-10-31 · 0 comments

Found by b18 (#1078). Probed by the architect on target/fast/nikaia at 0510bf6f. Both rows pass check and fail in rustc.

Row a, a named function handed to map over iter():

fn half(n: i64) -> i64 { return n / 2 }
fn main() {
    let xs = [1, 4, 6].iter().map(half).collect()
    print(xs.len())
}

rustc: “Type mismatch in function arguments: expected fn(&{integer}) -> _, found fn(i64) -> _”.

Row b, a filter_map lambda whose if yields a value or null:

fn main() {
    let xs = [1, 4, 6].iter().filter_map(fn(n) { if n > 1 { n / 2 } else { null } }).collect()
    print(xs.len())
}

rustc: “Mismatched types: expected reference &_, found type {integer}”.

Expected 3 and 2. The element of a copy list’s iter() is a copy value in Nikaia, while in Rust it is &i64. The lowering has to bridge that, with .copied() or a closure |x| half(*x), and the lambda’s if/null result has to become Some(..)/None of the value, not of a reference.

To build

  1. Row a: a named function handed where the Rust closure gets &T of a copy T lowers through a closure that dereferences (or .copied() before the adapter).
  2. Row b: the option result of a filter_map lambda over iter() of copy elements is typed by the value, so it lowers to Some(n / 2) / None.
  3. Test tests/compiler/tests/iter_copy_elements_into_code.nika + .stdout with both rows.

Generated by Claude Code

Back to Open Issues