Open and answer this issue on GitHub.
ready · opened 2026-11-23 · updated 2026-11-23 · 0 comments
A catch used as a value, on a call whose function returns String throws, yields a block Text from its handler while the success arm is the function’s EitherText. rustc refuses the generated match and the user sees NK1343.
use std::io
fn refuse(word: String) -> String throws {
if word == "x" { throw io::IoError::NotText("not text") }
return word
}
fn main() throws {
for word in ["x", "ok"] {
let got = refuse(word) catch {
match error {
io::IoError::NotText(message) => f"not text: {message}",
else => "else",
}
}
println(got)
}
}
Generated (block types):
let got = match refuse(word) {
Ok(value) => value, // EitherText<'_>
Err(error) => { let (error, __nikaia_site) = error.split(); match error {
io::IoError::NotText(ref message) => format!("not text: {}", message),
_ => nikaia_std::block::Text::from("else"), // Text
} },
};
rustc: E0308: match arms have incompatible types … expected EitherText<'_>, found Text.
catch, convert the handler’s text value to the representation of the call’s value (or lift the value arm to Text), the same way an if/match with mixed text arms is unified.tests/compiler/tests/: the probe above, with .stdout not text: not text / ok, --both-settings.The probe runs and prints both lines in both settings.
Found while testing the fix of the io::IoError text payloads on block types (ADR-327 D8); that test (ioerror_text_payload) prints inside each arm instead, so it does not depend on this.