ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.73k stars 2.54k forks source link

Compilation Segfault #8041

Closed ikskuh closed 1 year ago

ikskuh commented 3 years ago

While doing some code golfing, i found a bug in the compiler that crashes with a segfault when compiling this code:

pub fn main() !void {
    const p = @import("std").io.getStdOut().writer();
    var i: usize = 1;
    while (i < 101) : (i += 1) {
        try (if ((i % 15) == 0)
            p.print("FizzBuzz\n", .{})
        else if ((i % 5) == 0)
            p.print("Buzz\n", .{})
        else if ((i % 3) == 0)
            p.print("Fizz\n", .{})
        else
            p.print("{}\n", .{i}));
    }
}
hgmich commented 3 years ago

You can apparently also trigger (what I assume is the same bug) in a different case by doing an equivalent series of expressions with optionals and trying to coalesce them with orelse.

mikdusan commented 1 year ago

issue no longer exists

$ zig version
0.11.0-dev.1026+4172c2916
$ zig build-exe bug1.zig
# no segfault