-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Hi, I'm pretty new to Zig, so there may be something obvious that I'm missing. This is the error:
❯ ./zig-out/bin/rfcp
thread 364647 panic: reached unreachable code
/nix/store/n2620b80jfxfn7c80qdmp6ma9v71rjbl-zig-0.14.1/lib/zig/std/debug.zig:550:14: 0x1051b3d in assert (rfcp)
if (!ok) unreachable; // assertion failure
^
/home/zmitchell/.cache/zig/p/yazap-0.6.3-Z1t-EiLlAQCR5mUSOlF1PovnwyPcIUGeV02lAIVMUEOc/src/parser/Parser.zig:126:25: 0x10fac69 in highestPositionalArgIndex (rfcp)
std.debug.assert(pos_arg.index != null);
^
/home/zmitchell/.cache/zig/p/yazap-0.6.3-Z1t-EiLlAQCR5mUSOlF1PovnwyPcIUGeV02lAIVMUEOc/src/parser/Parser.zig:52:65: 0x10f524d in parse (rfcp)
const highest_pos_arg_index = self.highestPositionalArgIndex();
^
/home/zmitchell/.cache/zig/p/yazap-0.6.3-Z1t-EiLlAQCR5mUSOlF1PovnwyPcIUGeV02lAIVMUEOc/src/App.zig:124:30: 0x10ed0bd in parseFrom (rfcp)
var result = parser.parse() catch |err| {
^
/home/zmitchell/.cache/zig/p/yazap-0.6.3-Z1t-EiLlAQCR5mUSOlF1PovnwyPcIUGeV02lAIVMUEOc/src/App.zig:105:26: 0x10e7fe7 in parseProcess (rfcp)
return self.parseFrom(self.process_args.?[1..]);
^
/home/zmitchell/src/rfcp/src/cli.zig:31:45: 0x10e7c50 in fromApp (rfcp)
const matches = try app.parseProcess();
^
/home/zmitchell/src/rfcp/src/main.zig:15:38: 0x10e8259 in main (rfcp)
const args = try cli.Args.fromApp(&app);
^
/nix/store/n2620b80jfxfn7c80qdmp6ma9v71rjbl-zig-0.14.1/lib/zig/std/start.zig:660:37: 0x10e6dba in posixCallMainAndExit (rfcp)
const result = root.main() catch |err| {
^
/nix/store/n2620b80jfxfn7c80qdmp6ma9v71rjbl-zig-0.14.1/lib/zig/std/start.zig:271:5: 0x10e696d in _start (rfcp)
asm volatile (switch (native_arch) {
^
???:?:?: 0x0 in ??? (???)
fish: Job 1, './zig-out/bin/rfcp' terminated by signal SIGABRT (Abort)
These are the two files of my application so far:
main.zig
//! By convention, main.zig is where your main function lives in the case that
//! you are building an executable. If you are making a library, the convention
//! is to delete this file and start with root.zig instead.
const std = @import("std");
const cli = @import("cli.zig");
pub fn main() !void {
var allocator_state: std.heap.DebugAllocator(.{}) = .init;
defer _ = allocator_state.deinit();
const allocator = allocator_state.allocator();
var app = try cli.mkCli(allocator);
defer app.deinit();
const args = try cli.Args.fromApp(&app);
std.debug.print("mode: {s}", .{args.mode});
std.debug.print("src: {s}", .{args.src});
std.debug.print("dest: {s}", .{args.dest});
}cli.zig
const std = @import("std");
const yazap = @import("yazap");
pub fn mkCli(allocator: std.mem.Allocator) !yazap.App {
var app = yazap.App.init(allocator, "rfcp", "A really fast cp clone");
defer app.deinit();
var cli = app.rootCommand();
cli.setProperty(.help_on_empty_args);
// cli.setProperty(.positional_arg_required);
// The backend implementation to use during the copy.
try cli.addArg(yazap.Arg.singleValueOptionWithValidValues("mode", 'm', "Which back end implementation to use.", &[_][]const u8{"single"}));
// The source and destination arguments.
try cli.addArg(yazap.Arg.positional("src", "The source file or directory to copy", null));
try cli.addArg(yazap.Arg.positional("dest", "The destination file or directory to copy", null));
return app;
}
pub const Args = struct {
mode: []const u8,
src: []const u8,
dest: []const u8,
const Self = @This();
pub fn fromApp(app: *yazap.App) !Self {
const matches = try app.parseProcess();
const mode = matches.getSingleValue("mode").?;
const src = matches.getSingleValue("src").?;
const dest = matches.getSingleValue("dest").?;
return Self{ .mode = mode, .src = src, .dest = dest };
}
};Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working