-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviorstage1The process of building from source via WebAssembly and the C backend.The process of building from source via WebAssembly and the C backend.
Milestone
Description
Version : 0.4.0+d1b6f29d
This is similar to #834.
const std = @import("std");
const ints = []u32{ 42, 1337, 0xdeadbeef };
fn do_thing(int: u32) error{IsALeet}!void {
std.debug.warn("{}\n", int);
if (int == 1337) return error.IsALeet;
}
pub fn main() void {
inline for (ints) |int| {
do_thing(int) catch |_| continue;
std.debug.warn("not a leet\n");
}
}The code above gives a compiler crash.
$ gdb zig
GNU gdb (GDB) Fedora 8.2-6.fc29
...
(gdb) run build-exe main.zig
Starting program: zig build-exe main.zig
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff634a220 in llvm::BasicBlock::getContext() const ()
(gdb) bt
#0 0x00007ffff634a220 in llvm::BasicBlock::getContext() const ()
#1 0x00007ffff63dea89 in llvm::BranchInst::BranchInst(llvm::BasicBlock*, llvm::BasicBlock*, llvm::Value*, llvm::Instruction*) ()
#2 0x00007ffff63761e8 in LLVMBuildCondBr ()
#3 0x00007ffff250249a in ir_render_instruction(CodeGen*, IrExecutable*, IrInstruction*) [clone .isra.206] ()
#4 0x00007ffff2503cf5 in do_code_gen(CodeGen*) ()
#5 0x00007ffff2507407 in codegen_build_and_link(CodeGen*) ()
#6 0x00007ffff24302bd in main ()
A if on the error union will give a comptime control flow inside runtime block error :
pub fn main() void {
inline for (ints) |int| {
if (do_thing(int)) |_| {}
else |_| { continue; }
std.debug.warn("not a leet\n");
}
}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.
pub fn main() void {
inline for (ints) |int| blk: {
do_thing(int) catch |_| break :blk;
std.debug.warn("not a leet\n");
}
} $ zig build-exe main.zig
$ ./main
42
not a leet
1337
3735928559
not a leet
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviorstage1The process of building from source via WebAssembly and the C backend.The process of building from source via WebAssembly and the C backend.