New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
continue inside inline for cause compiler crash #2604
Comments
I think I had more or less the same bug on another snippet: const std = @import("std");
const builtin = @import("builtin");
const meta = std.meta;
test "foo" {
const Foo = union(enum) {
A: u32,
B: u32,
};
const key = Foo{ .A = 1 };
switch (@typeInfo(Foo)) {
// builtin.TypeId.Union => |info| {
builtin.TypeId.Union => |info| blk: {
if (info.tag_type) |tag_type| {
const tag = meta.activeTag(key);
inline for (info.fields) |field| {
const enum_field = field.enum_field.?;
if (enum_field.value == @enumToInt(tag)) {
std.debug.warn("{}", enum_field.name);
// return;
break :blk;
}
}
}
},
else => {},
}
}
Callstack:
In |
I just pushed a fix for the original test case, which now gives
Making this not a compile error needs to be a separate proposal. More examples need to be examined and an implementation will be nontrivial. @Sahnvour your test case still crashes, turns out it is a separate issue. |
I think I had the same issue? this fails to compile: export fn func() u32 {
var s : u32 = 0;
inline for ([_]u8{1,2}) |phase| {
var i: u32 = 0;
while (i<4) : (i+=1) {
if (phase == i)
continue;
s += i;
}
}
return s;
} And, if I reverse the export fn func() u32 {
var s : u32 = 0;
inline for ([_]u8{1,2}) |phase| {
var i: u32 = 0;
while (i<4) : (i+=1) {
if (phase != i) {
s += i;
}
}
}
return s;
} I'd guess it is related to control flow with 'goto' like constructs (had similar issues with |
I encountered this compiler error too while I was toying around, implementing a small parser combinator. Here's the implementation of fn OneOf(comptime rezolvrs: anytype) Rezolvr(RezolvrType(rezolvrs)) {
return struct {
fn rezolve(input: []const u8) Error!Result(RezolvrType(rezolvrs)) {
inline for (rezolvrs) |r| {
return r(input) catch continue;
}
return Error.TermRejected;
// Worked around it like this:
// if (rezolvrs.len == 0) return Error.TermRejected;
// return rezolvrs[0](input) catch OneOf(rezolvrs[1..])(input);
}
}.rezolve;
} I expected that the |
Works fine with
|
Version : 0.4.0+d1b6f29d
This is similar to #834.
The code above gives a compiler crash.
A
if
on the error union will give acomptime control flow inside runtime block
error :By the way, I don't think doing that should be an error since breaking on the inner block compile correctly, and is essentially the same thing.
The text was updated successfully, but these errors were encountered: