019 auto discharge branch constructor

✗ 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

input.kz

Supporting Files

fs.kcs
fs.kz
input.kcs

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