aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2019-04-28 12:45:50 +0200
committerAndrew Kelley <andrew@ziglang.org>2019-04-28 13:13:42 -0400
commit9902b604cb01072d4599035b59724731cf03fdbc (patch)
tree67d5deb790c0abca47b60b95c729dc0e10b93a38 /test
parent205e501e42b9a2e1d35afa0873311165100863ae (diff)
downloadzig-9902b604cb01072d4599035b59724731cf03fdbc.tar.gz
zig-9902b604cb01072d4599035b59724731cf03fdbc.zip
Fix generation of container initializers
The code creates temporary ConstExprValue with global_refs set to nullptr and that's carried over to the final value. Doing so prevents the deduplication mechanism to work correctly, causing all sorts of runtime crashes. Fixes #1636 Fixes #1608 (Even though it was already fixed by #1991)
Diffstat (limited to 'test')
-rw-r--r--test/stage1/behavior/struct.zig22
1 files changed, 20 insertions, 2 deletions
diff --git a/test/stage1/behavior/struct.zig b/test/stage1/behavior/struct.zig
index 62fb41ca28..114f06982b 100644
--- a/test/stage1/behavior/struct.zig
+++ b/test/stage1/behavior/struct.zig
@@ -2,8 +2,7 @@ const std = @import("std");
const expect = std.testing.expect;
const expectEqualSlices = std.testing.expectEqualSlices;
const builtin = @import("builtin");
-const maxInt = std.math.maxInt;
-
+const maxInt = std.math.maxInt;
const StructWithNoFields = struct {
fn add(a: i32, b: i32) i32 {
return a + b;
@@ -505,3 +504,22 @@ test "packed struct with u0 field access" {
var s = S{ .f0 = 0 };
comptime expect(s.f0 == 0);
}
+
+const S0 = struct{
+ bar: S1,
+
+ pub const S1 = struct{
+ value: u8,
+ };
+
+ fn init() @This() {
+ return S0{ .bar = S1{ .value = 123 } };
+ }
+};
+
+var g_foo: S0 = S0.init();
+
+test "access to global struct fields" {
+ g_foo.bar.value = 42;
+ expect(g_foo.bar.value == 42);
+}