zig icon indicating copy to clipboard operation
zig copied to clipboard

Compiler asserts when using PackedIntArray at comptime

Open cryptocode opened this issue 3 years ago • 1 comments
trafficstars

Zig Version

0.10.0-dev.359+fa84625ae

Steps to Reproduce

const std = @import("std");

pub fn main() void {
    comptime {
        var pack = std.PackedIntArray(u8, 2).initAllTo(0);
        _ = pack.get(0);
    }    
}

This repro case is similar to #7648 (which seems fixed at master), but the error and root cause seems sufficiently different to warrant a new issue.

Expected Behavior

Successful compile

Actual Behavior

stage1/analyze.cpp:5608 in hash_combine_const_val_array. This is a bug in the Zig compiler.

This is the actual assert:

assert(value->type == array->type->data.array.child_type);

Debugging the compiler a bit shows that value->type is u16 while child_type is u8

Note that replacing the int_count argument of 2 with 1 makes it compile. Also worth noting that the get call is required to trigger the bug (unlike the linked issue)

cryptocode avatar Jan 25 '22 16:01 cryptocode

This works fine on stage2 (tested on 0.10.0-dev.4418+99c3578f6)

cryptocode avatar Oct 16 '22 18:10 cryptocode