Skip to content

Commit c1fd7ed

Browse files
committed
add regression test for struct with optional list of self
closes #1735
1 parent 428a2fd commit c1fd7ed

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

test/stage1/behavior.zig

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ comptime {
2323
_ = @import("behavior/bugs/1486.zig");
2424
_ = @import("behavior/bugs/1500.zig");
2525
_ = @import("behavior/bugs/1607.zig");
26+
_ = @import("behavior/bugs/1735.zig");
2627
_ = @import("behavior/bugs/1851.zig");
2728
_ = @import("behavior/bugs/1914.zig");
2829
_ = @import("behavior/bugs/2006.zig");

test/stage1/behavior/bugs/1735.zig

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const std = @import("std");
2+
3+
const mystruct = struct {
4+
pending: ?listofstructs,
5+
};
6+
pub fn TailQueue(comptime T: type) type {
7+
return struct {
8+
const Self = @This();
9+
10+
pub const Node = struct {
11+
prev: ?*Node,
12+
next: ?*Node,
13+
data: T,
14+
};
15+
16+
first: ?*Node,
17+
last: ?*Node,
18+
len: usize,
19+
20+
pub fn init() Self {
21+
return Self{
22+
.first = null,
23+
.last = null,
24+
.len = 0,
25+
};
26+
}
27+
};
28+
}
29+
const listofstructs = TailQueue(mystruct);
30+
31+
const a = struct {
32+
const Self = @This();
33+
34+
foo: listofstructs,
35+
36+
pub fn init() Self {
37+
return Self{
38+
.foo = listofstructs.init(),
39+
};
40+
}
41+
};
42+
43+
test "intialization" {
44+
var t = a.init();
45+
std.testing.expect(t.foo.len == 0);
46+
}

0 commit comments

Comments
 (0)