Issue #2868: A bare block statement ending in a call that returns a value is refused by rustc (NK1343)

Open and answer this issue on GitHub.

bug, ready · opened 2026-11-28 · updated 2026-11-28 · 0 comments

Found while “io::lines() reads into a fixed pool and yields views” (#2851), builder’s step 4 report, at 471b3124.

Probe

use std::collections

fn main() throws {
    let mut seen: collections::BTreeSet[i64] = collections::BTreeSet()
    {
        let x = 1
        seen.insert(x)
    }
    println(f"{seen.len()}")
}

nikaia run gives NK1343 “Internal compiler error … mismatched types”: the lowered block ends in seen.insert(x) without ;, so the block’s value is the bool the insert returns where () is expected. Expected output: 1. NK1343 itself says the checker accepted the code and Rust refused what it became.

Governing decision

A block statement’s value is discarded like any expression statement’s (Part I, statements). This is plainly meant: the checker accepts it.

Cause

Untraced. Suspected in crates/nikaia-std/src/compiler/emit_stmt.nika, where a bare block statement’s tail is emitted without EmitTail::Statement. Settle it with nikaia lower of the probe and by reading the block’s emission.

To build

  1. When a bare block statement’s value is unused, its last expression is emitted as a statement (with ;). Test: tests/compiler/tests/a_bare_block_ending_in_a_call_with_a_value_runs.nika, .stdout (1).

Done when

The probe prints 1, and the commit carries Fixes #N.

Files and limits

emit_stmt.nika and its lowered file; no Rust by hand.

Facts: Lowering and lower-std

Back to Open Issues