Issue #2863: A match-bound optional passed to a ref T? parameter lowers to Rust that does not compile (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), by its builder.

Probe

On develop 67168136 (compiler source style, ref parameters as in crates/nikaia-std/src/compiler/*.nika):

struct R { m: bool }
enum I { F { r: R? } }

fn g(r: ref R?) -> bool { return r?.m ?? false }

fn f(i: ref I) -> bool {
	let r = match i { I::F { r } => r, }
	return g(r)
}

fn main() throws { println(f(I::F { r: R { m: true } })) }

target/fast/nikaia run p1.nika

Expected: prints true; the checker accepts it (Part III C.1: what the checker accepts compiles). Actual: error[NK1343]: Internal compiler error., rustc: “expected Option<&R>, found &Option<R>” at return g(r).

Cause

Suspected: emit_arg_opening (emit_core_args.nika) adds .as_ref() only where the argument is in facts.lent_args; a binding that is already a reference is not. To check: print lend and how for that argument.

To build

  1. Rerun the probe on today’s develop.
  2. An optional that is already a reference, passed to a ref T? parameter, is lowered with .as_ref() (or as the reference’s Option<&T>). Test: tests/compiler/tests/a_match_bound_optional_is_lent_to_a_ref_optional.nika, the probe, .stdout true.

Done when

The test prints true and failed before the fix; that commit carries Fixes #N. A Found: line per finding.

Files and limits

emit_core_args.nika, its lowered file.

Facts: Lowering and lower-std

Back to Open Issues