Got error during orelse 2 "var optinal integer"

Viewed 34

I'm a fresh new in Zig who test a few codes with "orelse". I tried to create 2 optional unsigned integer variables as following code and use orelse with them.

const std = @import("std");

pub fn main() !void {
    var value1: ?u32 = 123;
    var value2: ?u32 = 222;
    std.debug.print("value1 orelse value2: {}\n", .{value1 orelse value2});
}

My expectation, it should print "123". But I got an runtime error (or at least I understand it's):

zig run main.zig
broken LLVM module found: Instruction does not dominate all uses!
  %7 = getelementptr inbounds %"struct:26:52", %"struct:26:52"* %1, i32 0, i32 0, !dbg !2021
  %12 = getelementptr inbounds %"?u32", %"?u32"* %7, i32 0, i32 1, !dbg !2020
Instruction does not dominate all uses!
  %7 = getelementptr inbounds %"struct:26:52", %"struct:26:52"* %1, i32 0, i32 0, !dbg !2021
  %13 = getelementptr inbounds %"?u32", %"?u32"* %7, i32 0, i32 0, !dbg !2020

This is a bug in the Zig compiler.thread 1856201 panic:
Unable to dump stack trace: debug info stripped
make: *** [run] Abort trap: 6

So is it the correct expectation or it's a bug? If it's a bug, where should I post it (sorry I'm a newbie).

I'm using zig 0.9.1. Run on MacOS 12.5 (21G72)

Thanks for your taking time


UPDATE: Tried with suggestions:

  • v0.9.1: Define 3rd variable: value3 = value1 orelse value2; and print it
  • v0.10: upgrade and don't see this error anymore.
1 Answers

Tried with suggestions:

v0.9.1: Define 3rd variable: value3 = value1 orelse value2; and print it

v0.10: upgrade and don't see this error anymore.

Related