Created
July 10, 2022 06:23
-
-
Save hnakamur/32f6950a4722eddbcf3c30224aab79a8 to your computer and use it in GitHub Desktop.
Non-comptime switch cases not allowed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ zig test src/main.zig | |
./src/main.zig:11:28: error: cannot store runtime value in compile time variable | |
const d: u32 = c; | |
^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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