catch { -1 } over a call without a result, and return k in a function without oneOpen 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.
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:
catch { k } with let k: i64 = -1 gives NK1103, This catch hands back i64, but the value it guards is ().catch { "no" } gives the same NK1103 with String.let late: i64 = s.set(9; after: 7) catch { -1 } gives NK1103, This value is (), but the let declares i64.s.set(9; after: 7) catch { println("overtaken") } as a statement prints 9.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).
catch has the type of the value it guards”. Part III C (NK1103): a catch whose block hands back a value of another type than the one it guards is refused. Shape 1 is NK1103, This catch hands back i64, but the value it guards is ()., as catch { k } already gets.return that is not what was declared is refused. Shape 2 is NK1104 at the return.Suspected, read off the code; item 1 checks it with a probe.
check_core_flow_try_catch in crates/nikaia-std/src/compiler/check_core_flow.nika (around line 2007) accepts the handler when value.fits(answers). A number literal takes the type it is asked for (Part I 2.4: not typed until a use types it), so the literal -1 is suspected to come out as the guarded (), or as unknown, and to fit. catch { k }, whose type is fixed, reaches expect_type and is refused.check_core_returns in crates/nikaia-std/src/compiler/check_core_leaves.nika (around line 894) starts the comparison with let expected: Ty = state.expected?.clone() ?? return. A function without a result has no expected, so a value after return is never asked.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.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).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).(). 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.Fixes #N (#N being this issue’s number); the others say Part of #N.Found: line for each defect met on the way.crates/nikaia-std/src/compiler/check_core_flow.nika, crates/nikaia-std/src/compiler/check_core_leaves.nika, and what item 4 names; their lowered .rs is output.tests/compiler/tests/ (the two programs and their .stderr).catch: it writes what the checker hands it. The fix is in the checker, which must refuse both shapes before emitting.set(…; after:) and the lock: the program’s own check above fails the same way.