zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit c1fd7ed6e2815b3317b4cb82ce85bf44149d7002 (tree)
parent 428a2fdedd1d2d9ce6c7a3b28a379e4484468b9c
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Tue, 27 Aug 2019 14:06:17 -0400

add regression test for struct with optional list of self

closes #1735

Diffstat:
Mtest/stage1/behavior.zig | 1+
Atest/stage1/behavior/bugs/1735.zig | 46++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/test/stage1/behavior.zig b/test/stage1/behavior.zig @@ -23,6 +23,7 @@ comptime { _ = @import("behavior/bugs/1486.zig"); _ = @import("behavior/bugs/1500.zig"); _ = @import("behavior/bugs/1607.zig"); + _ = @import("behavior/bugs/1735.zig"); _ = @import("behavior/bugs/1851.zig"); _ = @import("behavior/bugs/1914.zig"); _ = @import("behavior/bugs/2006.zig"); diff --git a/test/stage1/behavior/bugs/1735.zig b/test/stage1/behavior/bugs/1735.zig @@ -0,0 +1,46 @@ +const std = @import("std"); + +const mystruct = struct { + pending: ?listofstructs, +}; +pub fn TailQueue(comptime T: type) type { + return struct { + const Self = @This(); + + pub const Node = struct { + prev: ?*Node, + next: ?*Node, + data: T, + }; + + first: ?*Node, + last: ?*Node, + len: usize, + + pub fn init() Self { + return Self{ + .first = null, + .last = null, + .len = 0, + }; + } + }; +} +const listofstructs = TailQueue(mystruct); + +const a = struct { + const Self = @This(); + + foo: listofstructs, + + pub fn init() Self { + return Self{ + .foo = listofstructs.init(), + }; + } +}; + +test "intialization" { + var t = a.init(); + std.testing.expect(t.foo.len == 0); +}