aboutsummaryrefslogtreecommitdiff
path: root/test/cases/compile_errors
diff options
context:
space:
mode:
Diffstat (limited to 'test/cases/compile_errors')
-rw-r--r--test/cases/compile_errors/capture_group_on_switch_prong_with_incompatible_payload_types.zig21
-rw-r--r--test/cases/compile_errors/switch_capture_incompatible_types.zig27
-rw-r--r--test/cases/compile_errors/switch_on_union_with_no_attached_enum.zig4
3 files changed, 29 insertions, 23 deletions
diff --git a/test/cases/compile_errors/capture_group_on_switch_prong_with_incompatible_payload_types.zig b/test/cases/compile_errors/capture_group_on_switch_prong_with_incompatible_payload_types.zig
deleted file mode 100644
index cff9a58bc6..0000000000
--- a/test/cases/compile_errors/capture_group_on_switch_prong_with_incompatible_payload_types.zig
+++ /dev/null
@@ -1,21 +0,0 @@
-const Union = union(enum) {
- A: usize,
- B: isize,
-};
-comptime {
- var u = Union{ .A = 8 };
- switch (u) {
- .A, .B => |e| {
- _ = e;
- unreachable;
- },
- }
-}
-
-// error
-// backend=stage2
-// target=native
-//
-// :8:20: error: capture group with incompatible types
-// :8:10: note: type 'usize' here
-// :8:14: note: type 'isize' here
diff --git a/test/cases/compile_errors/switch_capture_incompatible_types.zig b/test/cases/compile_errors/switch_capture_incompatible_types.zig
new file mode 100644
index 0000000000..b6de7d5bf5
--- /dev/null
+++ b/test/cases/compile_errors/switch_capture_incompatible_types.zig
@@ -0,0 +1,27 @@
+export fn f() void {
+ const U = union(enum) { a: u32, b: *u8 };
+ var u: U = undefined;
+ switch (u) {
+ .a, .b => |val| _ = val,
+ }
+}
+
+export fn g() void {
+ const U = union(enum) { a: u64, b: u32 };
+ var u: U = undefined;
+ switch (u) {
+ .a, .b => |*ptr| _ = ptr,
+ }
+}
+
+// error
+// backend=stage2
+// target=native
+//
+// :5:20: error: capture group with incompatible types
+// :5:20: note: incompatible types: 'u32' and '*u8'
+// :5:10: note: type 'u32' here
+// :5:14: note: type '*u8' here
+// :13:20: error: capture group with incompatible types
+// :13:14: note: pointer type child 'u32' cannot cast into resolved pointer type child 'u64'
+// :13:20: note: this coercion is only possible when capturing by value
diff --git a/test/cases/compile_errors/switch_on_union_with_no_attached_enum.zig b/test/cases/compile_errors/switch_on_union_with_no_attached_enum.zig
index 4d8742d32e..d9bc2abb91 100644
--- a/test/cases/compile_errors/switch_on_union_with_no_attached_enum.zig
+++ b/test/cases/compile_errors/switch_on_union_with_no_attached_enum.zig
@@ -4,12 +4,12 @@ const Payload = union {
C: bool,
};
export fn entry() void {
- const a = Payload { .A = 1234 };
+ const a = Payload{ .A = 1234 };
foo(&a);
}
fn foo(a: *const Payload) void {
switch (a.*) {
- Payload.A => {},
+ .A => {},
else => unreachable,
}
}