Zig: Compiler error when assigning slices of different dimensions.

Created on 1 Feb 2020  路  1Comment  路  Source: ziglang/zig

Maybe related to #3956.

The following code will cause the compiler to generate broken LLVM code on stage 1, master (e6a812c82):

const Data = struct {
    data: [][]const u8,

    pub fn init(d: [4]u8) Data {
        return Data {
            .data = d[0..3],
        };
    }
};

pub fn main() void {
    var data = Data.init([4]u8{1, 2, 3, 4});

    _ = data;
}

It exits with the following error:

broken LLVM module found: Stored value type does not match pointer operand type!
  store i8* %4, %"[]u8"** %3, !dbg !12057
 %"[]u8"*
This is a bug in the Zig compiler.
Unable to dump stack trace: debug info stripped

It does not appear when the indirection through init is taken away.

bug stage1

Most helpful comment

Reports error correctly on 68dbba212dd7393c90ab0e914dedeac975fa0224.

./test.zig:6:22: error: expected type '[][]const u8', found '[]const u8'
            .data = d[0..3],
                     ^

>All comments

Reports error correctly on 68dbba212dd7393c90ab0e914dedeac975fa0224.

./test.zig:6:22: error: expected type '[][]const u8', found '[]const u8'
            .data = d[0..3],
                     ^
Was this page helpful?
0 / 5 - 0 ratings

Related issues

dobkeratops picture dobkeratops  路  3Comments

daurnimator picture daurnimator  路  3Comments

andrewrk picture andrewrk  路  3Comments

andrewrk picture andrewrk  路  3Comments

zimmi picture zimmi  路  3Comments