aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn Schmidt <john.schmidt.h@gmail.com>2024-02-09 01:51:26 +0100
committerAndrew Kelley <andrew@ziglang.org>2024-02-26 16:55:17 -0800
commit7a045ede7ca26338dc553e1a0113d1de4daf1b95 (patch)
tree292417e9614e07a9e2416cfe5d720adfdb255f87 /test
parent3e79c0f18ce05c302c6117e66275db4fcdf033e4 (diff)
downloadzig-7a045ede7ca26338dc553e1a0113d1de4daf1b95.tar.gz
zig-7a045ede7ca26338dc553e1a0113d1de4daf1b95.zip
Check for inactive union field when calling fn at comptime
Reuse `unionFieldPtr` here to ensure that all the safety checks are included. Closes https://github.com/ziglang/zig/issues/18546.
Diffstat (limited to 'test')
-rw-r--r--test/cases/compile_errors/union_calling_inactive_field_as_fn.zig16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/cases/compile_errors/union_calling_inactive_field_as_fn.zig b/test/cases/compile_errors/union_calling_inactive_field_as_fn.zig
new file mode 100644
index 0000000000..0f2421945a
--- /dev/null
+++ b/test/cases/compile_errors/union_calling_inactive_field_as_fn.zig
@@ -0,0 +1,16 @@
+const U = union(enum) {
+ int: isize,
+ float: f64,
+};
+
+export fn entry() void {
+ const f = U{ .int = 20 };
+ _ = f.float();
+}
+
+// error
+// backend=stage2
+// target=native
+//
+// :8:10: error: access of union field 'float' while field 'int' is active
+// :1:11: note: union declared here