mirror of
https://github.com/ziglang/zig.git
synced 2025-12-12 01:03:13 +00:00
This commit adds a new optional argument to several Value methods which provides the ability to resolve types if it comes to it. This prevents having duplicated logic inside both Sema and Value. With this commit, the "struct contains slice of itself" test is passing by exploiting the new lazy_align Value Tag.
95 lines
2.6 KiB
Zig
95 lines
2.6 KiB
Zig
const builtin = @import("builtin");
|
|
const expect = @import("std").testing.expect;
|
|
|
|
const Node = struct {
|
|
payload: i32,
|
|
children: []Node,
|
|
};
|
|
|
|
const NodeAligned = struct {
|
|
payload: i32,
|
|
children: []align(@alignOf(NodeAligned)) NodeAligned,
|
|
};
|
|
|
|
test "struct contains slice of itself" {
|
|
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
|
|
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
|
|
var other_nodes = [_]Node{
|
|
Node{
|
|
.payload = 31,
|
|
.children = &[_]Node{},
|
|
},
|
|
Node{
|
|
.payload = 32,
|
|
.children = &[_]Node{},
|
|
},
|
|
};
|
|
var nodes = [_]Node{
|
|
Node{
|
|
.payload = 1,
|
|
.children = &[_]Node{},
|
|
},
|
|
Node{
|
|
.payload = 2,
|
|
.children = &[_]Node{},
|
|
},
|
|
Node{
|
|
.payload = 3,
|
|
.children = other_nodes[0..],
|
|
},
|
|
};
|
|
const root = Node{
|
|
.payload = 1234,
|
|
.children = nodes[0..],
|
|
};
|
|
try expect(root.payload == 1234);
|
|
try expect(root.children[0].payload == 1);
|
|
try expect(root.children[1].payload == 2);
|
|
try expect(root.children[2].payload == 3);
|
|
try expect(root.children[2].children[0].payload == 31);
|
|
try expect(root.children[2].children[1].payload == 32);
|
|
}
|
|
|
|
test "struct contains aligned slice of itself" {
|
|
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
|
|
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
|
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
|
|
|
var other_nodes = [_]NodeAligned{
|
|
NodeAligned{
|
|
.payload = 31,
|
|
.children = &[_]NodeAligned{},
|
|
},
|
|
NodeAligned{
|
|
.payload = 32,
|
|
.children = &[_]NodeAligned{},
|
|
},
|
|
};
|
|
var nodes = [_]NodeAligned{
|
|
NodeAligned{
|
|
.payload = 1,
|
|
.children = &[_]NodeAligned{},
|
|
},
|
|
NodeAligned{
|
|
.payload = 2,
|
|
.children = &[_]NodeAligned{},
|
|
},
|
|
NodeAligned{
|
|
.payload = 3,
|
|
.children = other_nodes[0..],
|
|
},
|
|
};
|
|
const root = NodeAligned{
|
|
.payload = 1234,
|
|
.children = nodes[0..],
|
|
};
|
|
try expect(root.payload == 1234);
|
|
try expect(root.children[0].payload == 1);
|
|
try expect(root.children[1].payload == 2);
|
|
try expect(root.children[2].payload == 3);
|
|
try expect(root.children[2].children[0].payload == 31);
|
|
try expect(root.children[2].children[1].payload == 32);
|
|
}
|