✗
Failing This test is currently failing.
Failed: frontend
Failure Output
error[KORU118]: 'File' is call-site syntax — it produces no runtime value and cannot appear in a return or resume type
--> /Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/330_PHANTOM_TYPES/330_019_auto_discharge_branch_constructor/fs.kz:4:1
hint: capture kinds (Expression, Source, File, EmbedFile, InvocationMeta) exist only as tor parameters; produce a runtime type instead Code
// PINS: an obligation held at a subflow's EXIT gets its close AUTO-INSERTED
// before the subflow returns — `check-file` ends still holding <opened!>
// from `app/fs:open`, and the produced program must print the close.
//
// HISTORY: written 2026-07-24 as a branch-constructor arm
// (`| opened _ -> "file exists"`); KORU021 (landed 2026-08-18) refuses
// named arms on bare-returning tors, so the pin could not run.
// Re-spelled 2026-08-25 onto bare-return grammar grounded on 310_006
// (bind-and-pipe off a bare return) and 330_074 (flow-defined tor whose
// params are visible in the body). The discharge-before-return claim is
// measured TRUE on this spelling: both lines print, close auto-inserted.
~import app/fs
~tor check-file { path: string } -> string
~check-file = app/fs:open(path): f |> say-exists()
~tor say-exists {} -> string
~proc say-exists|zig {
return "file exists";
}
~check-file(path: "test.txt")
Supporting Files
using static KoruHost;
static class KoruHost {
public class File {
public long handle;
}
}
~proc open|cs {
__koru_stdout_write($"Opening file: {path}\n");
return new File { handle = 42 };
}
~proc close|cs {
__koru_stdout_write($"Closing file (auto-discharged)\n");
}
const std = @import("std");
const File = struct { handle: i32 };
~pub tor open { path: string } -> *File<opened!>
~proc open|zig {
std.debug.print("Opening file: {s}\n", .{path});
const f = std.heap.page_allocator.create(File) catch unreachable;
f.* = File{ .handle = 42 };
return f;
}
~pub tor close { file: *File<!opened> }
~proc close|zig {
std.debug.print("Closing file (auto-discharged)\n", .{});
}
~proc say-exists|cs {
return "file exists";
}Actual
Opening file: test.txt
Closing file (auto-discharged)
Expected output
✓ Zig✓ C#Opening file: test.txt
Closing file (auto-discharged)
Emitted C# source
using static KoruHost;
static class KoruHost {
public class File {
public long handle;
}
}
static class main_module {
public static void __koru_stdout_write(object s) => global::System.Console.Out.Write(s);
public static void __koru_stderr_write(object s) => global::System.Console.Error.Write(s);
// The mutable handle carrier — `*String`-style resources are
// `new __KoruBox { data = … }` because C# anonymous types are
// read-only: `s.data = …` (std/string append/clear, handle
// mutation generally) needs a settable member. `object`, not
// `dynamic`: the field is storage — every `x.data` read reaches
// it through a dynamic-typed handle (`*T` Input fields, the
// `dynamic` borrow locals below), so the member itself only
// needs to hold the value, and `object` keeps the DLR out of
// the store/load path.
public class __KoruBox { public object data; }
// Textification for `{{ … }}` operands: C# bool ToStrings as
// `True` where Koru prints `true`, and the operand's static type
// is unknown at this boundary — a `(x) is bool` inline test would
// be a compile error on statically-typed operands instead. Generic
// on purpose: `dynamic` boxed every value-type operand — measured
// ~1s/10M elements on 012_threat_scanner — while T specializes to
// the operand's own ToString() with no box.
public static string __koru_str<T>(T v) => v is bool b ? (b ? "true" : "false") : v?.ToString();
public static class check_file_event {
public struct Input {
public string path;
}
public static string handler(Input __koru_input) {
var path = __koru_input.path;
var f = main_module.app_fs_open_event.handler(new app_fs_open_event.Input { path = (string)(path)});
var __ret1 = main_module.say_exists_event.handler(new say_exists_event.Input { });
{
var __koru_p_file = f;
__koru_stdout_write($"Closing file (auto-discharged)\n");
}
return (string)(__ret1);
return default;
}
}
public static class say_exists_event {
public struct Input {
}
public static string handler(Input __koru_input) {
return "file exists";
return default;
}
}
public static class app_fs_open_event {
public struct Input {
public string path;
}
public static dynamic handler(Input __koru_input) {
var path = __koru_input.path;
__koru_stdout_write($"Opening file: {path}\n");
return new File { handle = 42 };
return default;
}
}
public static class app_fs_close_event {
public struct Input {
public dynamic file;
}
public static object handler(Input __koru_input) {
var file = __koru_input.file;
__koru_stdout_write($"Closing file (auto-discharged)\n");
return default;
}
}
public static class koru_start_event {
public struct Input {
}
public struct Output {
public string tag;
public object done;
}
public static Output handler(Input __koru_input) => new Output { tag = "done" };
}
public static class koru_end_event {
public struct Input {
}
public struct Output {
public string tag;
public object done;
}
public static Output handler(Input __koru_input) => new Output { tag = "done" };
}
public static void flow0() {
main_module.check_file_event.handler(new check_file_event.Input { path = (string)("test.txt")});
}
public static void flow1() {
main_module.koru_start_event.handler(new koru_start_event.Input { });
}
public static void flow2() {
main_module.koru_end_event.handler(new koru_end_event.Input { });
}
}
static class Program {
static void Main() {
main_module.flow1();
main_module.flow0();
main_module.flow2();
}
}
Flows
subflow ~check-file click a branch to expand · @labels scroll to their anchor
open (path)
flow ~check-file click a branch to expand · @labels scroll to their anchor
check-file (path: "test.txt")
Test Configuration
MUST_RUN LANGUAGES: cs