Commit c1fd7ed6e2

Andrew Kelley <andrew@ziglang.org>
2019-08-27 20:06:17
add regression test for struct with optional list of self
closes #1735
1 parent 428a2fd
Changed files (2)
test
stage1
behavior
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);
+}
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");