-1 =>, -10..-1 =>)Open and answer this issue on GitHub.
ready · opened 2026-11-23 · updated 2026-11-23 · 0 comments
Found by the builder of “#2457” in the bug lane (Friction line of its report): it wrote an if chain because match refused -1 =>.
A literal pattern with a leading minus does not parse, neither alone nor as a range end.
Run on develop 8cd60de6f, binary ./target/fast/nikaia run:
fn main() {
let count = -1
match count {
1 => print("one"),
-1 => print("minus one"),
else => print("other"),
}
}
Actual: Error: Expected } here, but found -. at 5:9.
fn main() {
let t = -5
match t {
-10..-1 => print("negative"),
else => print("other"),
}
}
Actual: Error: Didn't expect - here. at 4:9.
Expected: minus one and negative.
Specification Part 10, §3.4 Pattern Matching (match): the pattern table lists literals as “1, "text", true, 'n' |
that value” and ranges 200..299 (inclusive); it neither allows nor refuses a negative literal, and no ADR refuses it. A negative integer or float is a literal value of the scrutinee’s type, so matching it is plainly meant; the supervisor approves this as an obvious extension (supervisor, 2026-11-23). Step 1 writes the text into §3.4. |
suspected: the pattern parser (crates/nikaia/src/parser/mod.rs, where range patterns are read) starts a literal pattern only at a number token and does not accept a unary - before it.
-N and -N.M are literal patterns, alone, in or-patterns and as either end of a range (-10..-1, -5..5); §3.4 says so; the two probes print minus one and negative. The commit that finishes step 3 carries Fixes #N.
1, -1, 2.5, "text", true, 'n'”; one sentence: a numeric literal pattern may carry a leading -, also as a range end (-10..-1). No new syntax beyond that.- directly followed by an integer or float literal where a literal pattern or a range end may stand, giving the negative literal. By CLAUDE.md, Written in Nikaia only: if that part of the parser can move into Nikaia directly, the fix moves it; otherwise the change stays in the Rust grammar block and the report lists it for #557 / #125. Test: tests/compiler/tests/a_negative_literal_is_a_match_pattern.nika (+ .stdout) with both probes and an or-pattern -1 | 1 =>.check_patterns.nika, emit_pattern.nika, emit_core_match.nika, the exhaustiveness and range checks): a negative literal and a negative range end check and emit as their value; an empty range (-1..-10) is refused as a positive one is. Test: extend the test of step 2 with the empty range in a .stderr case. Carries Fixes #N.Change: docs/specification/10-nikaia-light.md §3.4, the pattern parser, the pattern checker and emitter, the new test. Not: unary minus in expressions, constant patterns by name.
Writing an if chain or a guard (n if n == -1 =>) in our own code: a workaround for a gap.