aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2020-11-10 17:55:16 +0100
committerAndrew Kelley <andrew@ziglang.org>2020-11-10 17:21:49 -0500
commit4d4ab1e69a40fb11d19e93b42a02016f9d009aef (patch)
treeca4312aad89b1a198eab033f972ee2882d8ce04b /test
parent06a3a69e6f38798b1768976520b8db40c9a210bf (diff)
downloadzig-4d4ab1e69a40fb11d19e93b42a02016f9d009aef.tar.gz
zig-4d4ab1e69a40fb11d19e93b42a02016f9d009aef.zip
stage1: Fix comparison of unions containing zero-sized types
The code tried to be too smart and skipped the equality (returning true) if the payload type was zero-sized. This optimization is completely wrong when the union payload is a metatype! Fixes #7047
Diffstat (limited to 'test')
-rw-r--r--test/stage1/behavior.zig1
-rw-r--r--test/stage1/behavior/bugs/7047.zig22
2 files changed, 23 insertions, 0 deletions
diff --git a/test/stage1/behavior.zig b/test/stage1/behavior.zig
index 3434f6dbf4..ee7246cb36 100644
--- a/test/stage1/behavior.zig
+++ b/test/stage1/behavior.zig
@@ -56,6 +56,7 @@ comptime {
_ = @import("behavior/bugs/6456.zig");
_ = @import("behavior/bugs/6781.zig");
_ = @import("behavior/bugs/6850.zig");
+ _ = @import("behavior/bugs/7047.zig");
_ = @import("behavior/bugs/394.zig");
_ = @import("behavior/bugs/421.zig");
_ = @import("behavior/bugs/529.zig");
diff --git a/test/stage1/behavior/bugs/7047.zig b/test/stage1/behavior/bugs/7047.zig
new file mode 100644
index 0000000000..0704e97b48
--- /dev/null
+++ b/test/stage1/behavior/bugs/7047.zig
@@ -0,0 +1,22 @@
+const std = @import("std");
+
+const U = union(enum) {
+ T: type,
+ N: void,
+};
+
+fn S(comptime query: U) type {
+ return struct {
+ fn tag() type {
+ return query.T;
+ }
+ };
+}
+
+test "compiler doesn't consider equal unions with different 'type' payload" {
+ const s1 = S(U{ .T = u32 }).tag();
+ std.testing.expectEqual(u32, s1);
+
+ const s2 = S(U{ .T = u64 }).tag();
+ std.testing.expectEqual(u64, s2);
+}