Issue #2193: A number handed back where nothing is wanted reaches Rust as an internal compiler error (NK1343): catch { -1 } over a call without a result, and return k in a function without one

Open and answer this issue on GitHub.

ready · opened 2026-11-19 · updated 2026-11-19 · 0 comments

Found while drafting “The lock tests of std move into Nikaia programs” (#2189). No item of it waits for this: its race program (item 5) ends the handler with catch { return }, which works.

What happens today

Binary: target/release/nikaia (nikaia 0.1.0, built 2026-11-18 06:16 from develop), run in a scratch directory outside the checkout with nikaia run FILE.

1. A number literal as the replacement of a catch over a value of type (). SharedMut::set(…; after:) has no result and throws Overtaken (std.contracts):

fn main() throws {
    let s: SharedMut[i64] = SharedMut(7)
    let late = s.set(9; after: 7) catch { -1 }
    println(f"{s.get()}")
}
error[NK1343]: Internal compiler error.
  --> ice.nika:3:43
   |
 3 |     let late = s.set(9; after: 7) catch { -1 }
   |                                           ^^^
   |
   = note: Rustc output: `match` arms have incompatible types.
   = help: This is a bug in Nikaia, not in your program: the checker accepted it, and Rust refused the code it became. Please report it, with this message, at https://github.com/Nikaia-Foundation/Nikaia/issues.

Exit 101. catch { 3 } gives the same. Every other replacement is refused as it should be:

So only a number literal slips through, and only where the guarded value is (). It is not the lock: a function of the program’s own that throws and has no result gives the same NK1343 at the literal:

struct Bad { why: String }
impl Error for Bad { fn message(ref self) -> String { return self.why.clone() } }

fn check(n: i64) throws {
    if n > 5 {
        throw Bad { why: "big" }
    }
}

fn main() throws {
    let late = check(9) catch { -1 }
    println("done")
}
error[NK1343]: Internal compiler error.
   --> ice_own.nika:11:33
    |
 11 |     let late = check(9) catch { -1 }
    |                                 ^^^
    |
    = note: Rustc output: `match` arms have incompatible types.

2. A value after return in a function without a result.

fn nothing() {
    let k: i64 = 3
    return k
}

fn main() throws {
    nothing()
    println("done")
}
error[NK1343]: Internal compiler error.
  --> ret_var.nika:3:5
   |
 3 |     return k
   |     ^^^^^^^^
   |
   = note: Rustc output: mismatched types.
   = note: Try adding a return type.
   = help: This is a bug in Nikaia, not in your program: the checker accepted it, and Rust refused the code it became. Please report it, with this message, at https://github.com/Nikaia-Foundation/Nikaia/issues.

Exit 101. return 3 and return "x" give the same.

No open issue names either shape (searched the titles for NK1343, catch, return).

Expected

Cause

Suspected, read off the code; item 1 checks it with a probe.

To build

  1. Check the cause of shape 1: run nikaia run scripts/where.nika -- check_core_flow_try_catch and a probe that prints the handler’s type for catch { -1 } and for catch { k } beside a guarded (). A cause shown false is answered wrong I7: ... in the report.
  2. Refuse shape 1 with NK1103: a number literal ending a catch block over a guarded () is asked against () like any other value. Test: tests/compiler/tests/a_catch_handing_back_a_number_over_nothing_is_refused.nika with its .stderr (the NK1103 of the probe above, on SharedMut::set(…; after:) and on a function of the program’s own that throws and has no result).
  3. Refuse shape 2 with NK1104: in a function without a result, return with a value is refused, the help saying to drop the value or declare the result. Test: tests/compiler/tests/a_return_with_a_value_in_a_function_without_a_result_is_refused.nika with its .stderr (a variable, a number literal and a text literal, each in its own function).
  4. Sweep for the rule (I10): every place that compares a value against an expected type and returns early when the expected type is missing or (). Name each one checked in the report; one that also lets a value through to rustc gets its case in the test of item 2 or 3.

Done when

Files and limits

Ruled out

Back to Open Issues