Skip to content

Instantly share code, notes, and snippets.

@MichaelBelousov
Last active June 2, 2022 20:13
Show Gist options
  • Save MichaelBelousov/03dadd8a5e3e030e2e312f95b0a92344 to your computer and use it in GitHub Desktop.
Save MichaelBelousov/03dadd8a5e3e030e2e312f95b0a92344 to your computer and use it in GitHub Desktop.
zig compile error
//! parser for nodelang written in zig
pub const Tok = enum {
colon,
other, // need at least two here to trigger it
};
const Token = struct {
tok: Tok,
str: []const u8,
pub fn new(tok: Tok, str: []const u8) Token {
return Token{.tok=tok, .str=str};
}
};
fn parseMany(comptime tokOrNodeTypes: [2]Tok) !?u32 {
// inline for seems to be necessary, I tried manually inlining
inline for (tokOrNodeTypes) |tokType| {
// manually inlining Token.new prevents the compiler segfault from appearing
const tok = try @as(anyerror!Token, Token.new(Tok.colon, ":"));
// being in the else clause seems to be necessary
if (tok.tok != tokType) {} else {
while (true) {
// returning instead of breaking seems to be necessary
return null;
}
}
}
return 0;
}
pub fn main() !void {
_ = try parseMany(.{Tok.colon, Tok.colon});
}
@MichaelBelousov
Copy link
Author

fails to compile on: compiler: 0.10.0-dev.290+3901b6fb0

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