025 auto discharge disabled

✓ Passing This code compiles and runs correctly.

Code

// TEST: Auto-discharge disabled via --auto-discharge=disable flag
//
// When auto-discharge is disabled, the phantom semantic checker should
// report KORU030 for unsatisfied cleanup obligations.
//
// This test verifies that:
// 1. The --auto-discharge=disable flag works
// 2. The phantom checker correctly catches obligations when not auto-discharged
//
// Expected: KORU030 error for unsatisfied obligation

~import "$app/fs"

// Open a file but don't close it
// Without auto-discharge, this should error
~app.fs:open(path: "test.txt")
| opened _ |> _
input.kz

Error Verification

Expected Error Pattern

error[KORU030]: Resource

Actual Compiler Output ✓ Pattern matched

[PHASE 2.4] Calling run_pass for transforms\n[PHASE 2.5] Executing comptime_main() - running comptime flows
[PHASE 2.5] Comptime flows complete (29 items)
[PHASE 2.6] Rescanning transformed AST (29 items)
[PHASE 2.6] Rescan complete: 25 comptime events found
  [0] std.compiler:requires
  [1] std.compiler:flag.declare
  [2] std.compiler:command.declare
  [3] std.compiler:coordinate
  [4] std.compiler:context_create
  [5] std.testing:test
  [6] std.testing:validate_mocks
  [7] std.testing:test.with_harness
  [8] std.testing:test.harness
  [9] std.testing:assert
  [10] std.testing:test.property.equivalent
  [11] std.deps:deps
  [12] std.deps:requires.system
  [13] std.deps:requires.zig
  [14] std.control:if
  [15] std.control:for
  [16] std.control:capture
  [17] std.control:const
  [18] std.build:requires
  [19] std.build:variants
  [20] std.build:config
  [21] std.build:command.sh
  [22] std.build:command.zig
  [23] std.build:step
  [24] std.template:define

[PHANTOM-KORU] Starting phantom check proc...
error[KORU030]: Resource '_.file' with cleanup obligation 'app.fs:opened!' was not disposed. Call the disposal event explicitly.
  --> phantom_semantic_check:17:0

❌ Compiler coordination error: Phantom semantic validation failed
error: CompilerCoordinationFailed
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/330_PHANTOM_TYPES/330_025_auto_discharge_disabled/backend.zig:9390:17: 0x10290a433 in emit (backend)
                return error.CompilerCoordinationFailed;
                ^
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/330_PHANTOM_TYPES/330_025_auto_discharge_disabled/backend.zig:9474:28: 0x10290b1bf in main (backend)
    const generated_code = try RuntimeEmitter.emit(compile_allocator, final_ast);
                           ^

Imported Files

// Library module: fs
// Single disposal event - auto-discharge should work

const std = @import("std");

const File = struct { handle: i32 };

// Open a file - returns opened! state (requires cleanup)
~pub event open { path: []const u8 }
| opened { file: *File[opened!] }

~proc open {
    std.debug.print("Opening file\n", .{});
    const f = std.heap.page_allocator.create(File) catch unreachable;
    f.* = File{ .handle = 42 };
    return .{ .opened = .{ .file = f } };
}

// Close - the ONLY consumer of [!opened]
~pub event close { file: *File[!opened] }
| closed {}

~proc close {
    std.debug.print("Closing file (auto-discharged)\n", .{});
    return .{ .closed = .{} };
}
fs.kz

Test Configuration

MUST_FAIL

Compiler Flags:

--auto-discharge=disable