ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.21k stars 2.5k forks source link

unexpected compile error: dependency loop #6309

Closed WoodyAtHome closed 6 months ago

WoodyAtHome commented 4 years ago

main.zig:

const std = @import("std");

const A = struct {
    b_map: ?Map, // line a: comment this line and the compiler crashes
};

const B = struct {
    a_ptr: *A,
};

const Map = std.AutoHashMap(*B, void);

test "Test" {
    // var  a = A{ .b_map = null }; // line b: uncomment this line and no more dependency error
    var b_s = Map.init(std.testing.allocator);
    defer b_s.deinit();
}

zig test main.zig gives an error: main.zig:4:13: error: dependency loop detected ....

Now uncomment line b, zig test main.zig is ok, All 1 tests passed.

I guess the size of the structs should be known at comptime.

By the way: uncomment line a and line b and zig test main.zig crashes

zig version 0.6.0+749417a1f

Vexu commented 6 months ago

Fixed in master.