diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-09-04 15:28:13 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-09-04 15:28:35 -0400 |
| commit | 68db9d5074cece234efa3a5352fe6cd36d210455 (patch) | |
| tree | b79ead870777d9d90ab809b70a687c77af20df0d /test/compile_errors.zig | |
| parent | 36828a2e6aa6879641bf6980379dd806b6f479a1 (diff) | |
| download | zig-68db9d5074cece234efa3a5352fe6cd36d210455.tar.gz zig-68db9d5074cece234efa3a5352fe6cd36d210455.zip | |
add compile error for comptime control flow inside runtime block
closes #834
Diffstat (limited to 'test/compile_errors.zig')
| -rw-r--r-- | test/compile_errors.zig | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 9979ed666c..6930f346e2 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -2,6 +2,116 @@ const tests = @import("tests.zig"); pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add( + "comptime continue inside runtime switch", + \\export fn entry() void { + \\ var p: i32 = undefined; + \\ comptime var q = true; + \\ inline while (q) { + \\ switch (p) { + \\ 11 => continue, + \\ else => {}, + \\ } + \\ q = false; + \\ } + \\} + , + ".tmp_source.zig:6:19: error: comptime control flow inside runtime block", + ".tmp_source.zig:5:9: note: runtime block created here", + ); + + cases.add( + "comptime continue inside runtime while error", + \\export fn entry() void { + \\ var p: error!usize = undefined; + \\ comptime var q = true; + \\ outer: inline while (q) { + \\ while (p) |_| { + \\ continue :outer; + \\ } else |_| {} + \\ q = false; + \\ } + \\} + , + ".tmp_source.zig:6:13: error: comptime control flow inside runtime block", + ".tmp_source.zig:5:9: note: runtime block created here", + ); + + cases.add( + "comptime continue inside runtime while optional", + \\export fn entry() void { + \\ var p: ?usize = undefined; + \\ comptime var q = true; + \\ outer: inline while (q) { + \\ while (p) |_| continue :outer; + \\ q = false; + \\ } + \\} + , + ".tmp_source.zig:5:23: error: comptime control flow inside runtime block", + ".tmp_source.zig:5:9: note: runtime block created here", + ); + + cases.add( + "comptime continue inside runtime while bool", + \\export fn entry() void { + \\ var p: usize = undefined; + \\ comptime var q = true; + \\ outer: inline while (q) { + \\ while (p == 11) continue :outer; + \\ q = false; + \\ } + \\} + , + ".tmp_source.zig:5:25: error: comptime control flow inside runtime block", + ".tmp_source.zig:5:9: note: runtime block created here", + ); + + cases.add( + "comptime continue inside runtime if error", + \\export fn entry() void { + \\ var p: error!i32 = undefined; + \\ comptime var q = true; + \\ inline while (q) { + \\ if (p) |_| continue else |_| {} + \\ q = false; + \\ } + \\} + , + ".tmp_source.zig:5:20: error: comptime control flow inside runtime block", + ".tmp_source.zig:5:9: note: runtime block created here", + ); + + cases.add( + "comptime continue inside runtime if optional", + \\export fn entry() void { + \\ var p: ?i32 = undefined; + \\ comptime var q = true; + \\ inline while (q) { + \\ if (p) |_| continue; + \\ q = false; + \\ } + \\} + , + ".tmp_source.zig:5:20: error: comptime control flow inside runtime block", + ".tmp_source.zig:5:9: note: runtime block created here", + ); + + cases.add( + "comptime continue inside runtime if bool", + \\export fn entry() void { + \\ var p: usize = undefined; + \\ comptime var q = true; + \\ inline while (q) { + \\ if (p == 11) continue; + \\ q = false; + \\ } + \\} + , + ".tmp_source.zig:5:22: error: comptime control flow inside runtime block", + ".tmp_source.zig:5:9: note: runtime block created here", + ); + + cases.add( "switch with invalid expression parameter", \\export fn entry() void { \\ Test(i32); |
