Skip to content

Instantly share code, notes, and snippets.

@hnakamur
Created July 10, 2022 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hnakamur/32f6950a4722eddbcf3c30224aab79a8 to your computer and use it in GitHub Desktop.
Save hnakamur/32f6950a4722eddbcf3c30224aab79a8 to your computer and use it in GitHub Desktop.
Non-comptime switch cases not allowed
$ zig test src/main.zig
./src/main.zig:11:28: error: cannot store runtime value in compile time variable
const d: u32 = c;
^
const std = @import("std");
const expect = std.testing.expect;
test "switch" {
const a: u64 = 105;
var c: u32 = 5;
const b = switch (a) {
1, 2, 3 => 0,
5...100 => 1,
blk: {
const d: u32 = c;
const e: u32 = 100;
break :blk d + e;
} => 7,
else => 9,
};
try expect(b == 7);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment