Skip to content

Instantly share code, notes, and snippets.

@kbd
Created March 1, 2021 00:10
Show Gist options
  • Save kbd/0a19b1387e3f64f1ffda8d7f16b71b73 to your computer and use it in GitHub Desktop.
Save kbd/0a19b1387e3f64f1ffda8d7f16b71b73 to your computer and use it in GitHub Desktop.
$ zig run repo_status.zig
./repo_status.zig:426:17: error: comptime control flow inside runtime block
continue;
^
./repo_status.zig:425:13: note: runtime block created here
if (num == 0)
^
./repo_status.zig:484:5: note: referenced here
try writeStatusStr(shell, status);
^
$ zig run repo_status.zig
./repo_status.zig:418:5: error: unable to evaluate constant expression
for (format) |f| {
^
./repo_status.zig:484:5: note: referenced here
try writeStatusStr(shell, status);
^
var format = .{
// using arrays over tuples failed because they're comptime
.{.color = C.green, .token = "↑", .status = Status.ahead},
.{.color = C.red, .token = "↓", .status = Status.behind},
.{.color = C.green, .token = "●", .status = Status.staged},
.{.color = C.yellow, .token = "+", .status = Status.modified},
.{.color = C.red, .token = "-", .status = Status.removed},
.{.color = C.cyan, .token = "…", .status = Status.untracked},
.{.color = C.blue, .token = "⚑", .status = Status.stashed},
.{.color = C.red, .token = "✖", .status = Status.conflicted},
};
// print stats
var printed_space = false;
for (format) |f| {
if (f.status == Status.stashed) {
var stashstr = ""; // formatStashes(status);
if (std.mem.eql(u8, stashstr, ""))
continue;
} else {
var num = status.status[@enumToInt(f.status)];
if (num == 0)
continue;
}
if (!printed_space){
try print(" ", .{});
printed_space = true;
}
try styleWrite(shell, f.color, f.token);
try styleWrite(shell, f.color, numstr);
@kbd
Copy link
Author

kbd commented Mar 1, 2021

This worked, no continues:

    // print stats
    var printed_space = false;
    inline for (format) |f| {
        var skip = false;
        var str: Str = undefined;
        if (f.status == Status.stashed) {
            str = ""; // formatStashes(status);
        } else {
            var num = status.status[@enumToInt(f.status)];
            if (num == 0) {
                str = "";
            } else {
                var buffer: [10]u8 = undefined;
                const buf = buffer[0..];
                str = try std.fmt.bufPrint(buf, "{}", .{num});
            }
        }
        if (!std.mem.eql(u8, str, "")) {
            if (!printed_space){
                try print(" ", .{});
                printed_space = true;
            }
            try styleWrite(shell, f.color, f.token);
            try styleWrite(shell, f.color, str);
        }
    }

@kbd
Copy link
Author

kbd commented Mar 1, 2021

Oh no:

When I added:

pub const io_mode = .evented;
$ zig build-exe repo_status.zig
broken LLVM module found: Basic Block in function 'std.child_process.ChildProcess.spawnPosix' does not have terminator!
label %OkResume
Instruction does not dominate all uses!
  %28 = load { %std.child_process.Term, i16 }*, { %std.child_process.Term, i16 }** %6, align 8, !dbg !7211
  %41 = bitcast { %std.child_process.Term, i16 }* %28 to i8*, !dbg !7211

This is a bug in the Zig compiler.
Unable to dump stack trace: debug info stripped
zsh: abort      zig build-exe repo_status.zig

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment