Issue #2844: A pattern binding over a value read from a map compares with a number as &i64 == i64 (NK1343)

Open and answer this issue on GitHub.

ready, bugs, queued · opened 2026-11-28 · updated 2026-11-29 · 0 comments

Found while “A held view is checked against the buffer the plan names” (#2842), by its builder.

Probe

On develop 65e66b1a (pushed), target/fast/nikaia built from it, outside the shared checkout:

use std::collections

enum KeepAt {
	Element(i64),
	Frame,
}

fn same(map: collections::HashMap[String, KeepAt], buffer: i64) -> bool {
	let keep = map.get("a") ?? return false
	match keep {
		KeepAt::Element(own) => return own == buffer,
		KeepAt::Frame => return false,
	}
}

fn main() throws {
	let mut m: collections::HashMap[String, KeepAt] = collections::HashMap()
	m.insert("a", KeepAt::Element(3))
	println(same(m, 3))
}

nikaia run q1.nika

Expected: prints true (Part I 6.5: a binding of a pattern over a borrowed value is a view of it, compared as the value). Actual: error[NK1343]: Internal compiler error., Rustc output: “can’t compare &i64 with i64.”

Cause

Suspected: the binding own of an enum pattern matched against keep, a value read from map.get(..), lowers as &i64, and == with an i64 is written without a dereference. Not traced; nikaia run scripts/where.nika -- emit_core_match is the place to start (match lowering, emit_core_match.nika). To check: the same with own > buffer and with a String payload.

Workaround to remove

crates/nikaia-std/src/compiler/buffers.nika (KeepAt::Element(own) => own.clone() == buffer && held_in(held, arg, buffer), written by #2842’s run to get past this). The fix removes the .clone() there.

To build

  1. Rerun the probe on today’s develop.
  2. Fix the comparison of a pattern binding over a borrowed value with an owned value of its type. Test: tests/compiler/tests/a_pattern_binding_of_a_map_value_compares_with_a_number.nika, the probe, .stdout true. Remove the workaround above in the same commit.

Done when

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

Files and limits

emit_core_match.nika or the comparison’s emitter, buffers.nika (the workaround), their lowered files.

Facts: Lowering and lower-std

Back to Open Issues