aboutsummaryrefslogtreecommitdiff
path: root/test/cases/compile_errors
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-10-03 23:43:09 -0400
committerGitHub <noreply@github.com>2022-10-03 23:43:09 -0400
commitff534d22676b8a934acf1931f91d70c554a4bdca (patch)
treed04b360f7831f6428d13a85d9d9c0d7c04fc1079 /test/cases/compile_errors
parent9d5462dcb5b4b4601bdf2e628b9d80fb74000cb2 (diff)
parent17eea918aee98ca29c3762a7ecd568d2f14f66ef (diff)
downloadzig-ff534d22676b8a934acf1931f91d70c554a4bdca.tar.gz
zig-ff534d22676b8a934acf1931f91d70c554a4bdca.zip
Merge pull request #12979 from Vexu/inline-switch
Implement inline switch cases
Diffstat (limited to 'test/cases/compile_errors')
-rw-r--r--test/cases/compile_errors/inline_underscore_prong.zig15
-rw-r--r--test/cases/compile_errors/invalid_inline_else_type.zig27
-rw-r--r--test/cases/compile_errors/invalid_tag_capture.zig15
-rw-r--r--test/cases/compile_errors/tag_capture_on_non_inline_prong.zig14
4 files changed, 71 insertions, 0 deletions
diff --git a/test/cases/compile_errors/inline_underscore_prong.zig b/test/cases/compile_errors/inline_underscore_prong.zig
new file mode 100644
index 0000000000..12e20e65bc
--- /dev/null
+++ b/test/cases/compile_errors/inline_underscore_prong.zig
@@ -0,0 +1,15 @@
+const E = enum(u8) { a, b, c, d, _ };
+pub export fn entry() void {
+ var x: E = .a;
+ switch (x) {
+ inline .a, .b => |aorb| @compileLog(aorb),
+ .c, .d => |cord| @compileLog(cord),
+ inline _ => {},
+ }
+}
+
+// error
+// backend=stage2
+// target=native
+//
+// :7:16: error: cannot inline '_' prong
diff --git a/test/cases/compile_errors/invalid_inline_else_type.zig b/test/cases/compile_errors/invalid_inline_else_type.zig
new file mode 100644
index 0000000000..2d52fca43e
--- /dev/null
+++ b/test/cases/compile_errors/invalid_inline_else_type.zig
@@ -0,0 +1,27 @@
+pub export fn entry1() void {
+ var a: anyerror = undefined;
+ switch (a) {
+ inline else => {},
+ }
+}
+const E = enum(u8) { a, _ };
+pub export fn entry2() void {
+ var a: E = undefined;
+ switch (a) {
+ inline else => {},
+ }
+}
+pub export fn entry3() void {
+ var a: *u32 = undefined;
+ switch (a) {
+ inline else => {},
+ }
+}
+
+// error
+// backend=stage2
+// target=native
+//
+// :4:21: error: cannot enumerate values of type 'anyerror' for 'inline else'
+// :11:21: error: cannot enumerate values of type 'tmp.E' for 'inline else'
+// :17:21: error: cannot enumerate values of type '*u32' for 'inline else'
diff --git a/test/cases/compile_errors/invalid_tag_capture.zig b/test/cases/compile_errors/invalid_tag_capture.zig
new file mode 100644
index 0000000000..2cb9135792
--- /dev/null
+++ b/test/cases/compile_errors/invalid_tag_capture.zig
@@ -0,0 +1,15 @@
+const E = enum { a, b, c, d };
+pub export fn entry() void {
+ var x: E = .a;
+ switch (x) {
+ inline .a, .b => |aorb, d| @compileLog(aorb, d),
+ inline .c, .d => |*cord| @compileLog(cord),
+ }
+}
+
+// error
+// backend=stage2
+// target=native
+//
+// :5:33: error: cannot capture tag of non-union type 'tmp.E'
+// :1:11: note: enum declared here
diff --git a/test/cases/compile_errors/tag_capture_on_non_inline_prong.zig b/test/cases/compile_errors/tag_capture_on_non_inline_prong.zig
new file mode 100644
index 0000000000..b525aa4db3
--- /dev/null
+++ b/test/cases/compile_errors/tag_capture_on_non_inline_prong.zig
@@ -0,0 +1,14 @@
+const E = enum { a, b, c, d };
+pub export fn entry() void {
+ var x: E = .a;
+ switch (x) {
+ .a, .b => |aorb, d| @compileLog(aorb, d),
+ inline .c, .d => |*cord| @compileLog(cord),
+ }
+}
+
+// error
+// backend=stage2
+// target=native
+//
+// :5:26: error: tag capture on non-inline prong