authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-27 14:06:17-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-27 14:06:17-04:00
logc1fd7ed6e2815b3317b4cb82ce85bf44149d7002
treed269f7365be2f7343ee778605c212e540064cb1a
parent428a2fdedd1d2d9ce6c7a3b28a379e4484468b9c
signaturelock-open Commit is signed but in an unrecognized format.

add regression test for struct with optional list of self

closes #1735

2 files changed, 47 insertions(+), 0 deletions(-)

test/stage1/behavior.zig+1
......@@ -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 created+46
......@@ -0,0 +1,46 @@
1const std = @import("std");
2
3const mystruct = struct {
4 pending: ?listofstructs,
5};
6pub 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}
29const listofstructs = TailQueue(mystruct);
30
31const 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
43test "intialization" {
44 var t = a.init();
45 std.testing.expect(t.foo.len == 0);
46}