aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2023-08-12 01:56:39 -0400
committerJacob Young <jacobly0@users.noreply.github.com>2023-08-12 02:22:26 -0400
commit41575fa868f4b75b79bf5f774b66bb9a7b1ab142 (patch)
treef7038b14c37cf43074f52001c2a151ace5796ee9 /test
parentce7acf1296f7d38e6ee1b24e7aa85864198dd8fa (diff)
downloadzig-41575fa868f4b75b79bf5f774b66bb9a7b1ab142.tar.gz
zig-41575fa868f4b75b79bf5f774b66bb9a7b1ab142.zip
AstGen: fix src loc for invalid switch expression rls coercions
Diffstat (limited to 'test')
-rw-r--r--test/cases/compile_errors/invalid_switch_expr_result_location_coercion.zig46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/cases/compile_errors/invalid_switch_expr_result_location_coercion.zig b/test/cases/compile_errors/invalid_switch_expr_result_location_coercion.zig
new file mode 100644
index 0000000000..d0fc87ae8d
--- /dev/null
+++ b/test/cases/compile_errors/invalid_switch_expr_result_location_coercion.zig
@@ -0,0 +1,46 @@
+const Enum = enum(u8) { first, second, _ };
+
+export fn invalidFirstProng(enum_value: Enum) u8 {
+ const result: u8 = switch (enum_value) {
+ .first => 256,
+ .second => 0,
+ else => 0,
+ };
+ return result;
+}
+
+export fn invalidSecondProng(enum_value: Enum) u8 {
+ const result: u8 = switch (enum_value) {
+ .first => 0,
+ .second => 256,
+ _ => 0,
+ };
+ return result;
+}
+
+export fn invalidElseProng(enum_value: Enum) u8 {
+ const result: u8 = switch (enum_value) {
+ .first => 0,
+ .second => 0,
+ else => 256,
+ };
+ return result;
+}
+
+export fn invalidNonExhaustiveProng(enum_value: Enum) u8 {
+ const result: u8 = switch (enum_value) {
+ .first => 0,
+ .second => 0,
+ _ => 256,
+ };
+ return result;
+}
+
+// error
+// backend=stage2
+// target=native
+//
+// :5:19: error: type 'u8' cannot represent integer value '256'
+// :15:20: error: type 'u8' cannot represent integer value '256'
+// :25:17: error: type 'u8' cannot represent integer value '256'
+// :34:14: error: type 'u8' cannot represent integer value '256'