From c1fd7ed6e2815b3317b4cb82ce85bf44149d7002 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 27 Aug 2019 14:06:17 -0400 Subject: [PATCH] add regression test for struct with optional list of self closes #1735 --- test/stage1/behavior.zig | 1 + test/stage1/behavior/bugs/1735.zig | 46 ++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 test/stage1/behavior/bugs/1735.zig diff --git a/test/stage1/behavior.zig b/test/stage1/behavior.zig index d35b467bd1617438cfa988b74cf299e9454824ec..d891b4200bac4aadf128a7bd5900e76c755e6d98 100644 --- 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 new file mode 100644 index 0000000000000000000000000000000000000000..e757b5157c6c9a710dfd19f3c3200917a0cf28a6 --- /dev/null +++ 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); +} -- 2.54.0