aboutsummaryrefslogtreecommitdiff
path: root/test/compile_errors.zig
diff options
context:
space:
mode:
authorkristopher tate <kt@connectfree.co.jp>2018-08-03 02:55:31 +0900
committerAndrew Kelley <superjoe30@gmail.com>2018-08-03 02:57:17 -0400
commit298abbcff86629273f24891d243fb6e503392e8f (patch)
treef5554887205c70c2679e79ba3e5d8cf00daec3b1 /test/compile_errors.zig
parentfb05b96492f4fb1476106bf735788ac16f69c7ef (diff)
downloadzig-298abbcff86629273f24891d243fb6e503392e8f.tar.gz
zig-298abbcff86629273f24891d243fb6e503392e8f.zip
better support for `_` identifier
* disallow variable declaration of `_` * prevent `_` from shadowing itself * prevent read access of `_` closes #1204 closes #1320
Diffstat (limited to 'test/compile_errors.zig')
-rw-r--r--test/compile_errors.zig58
1 files changed, 58 insertions, 0 deletions
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
index 948d212e58..56b2c51d74 100644
--- a/test/compile_errors.zig
+++ b/test/compile_errors.zig
@@ -23,6 +23,64 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
);
cases.add(
+ "`_` is not a declarable symbol",
+ \\export fn f1() usize {
+ \\ var _: usize = 2;
+ \\ return _;
+ \\}
+ ,
+ ".tmp_source.zig:2:5: error: `_` is not a declarable symbol",
+ ".tmp_source.zig:3:12: error: use of undeclared identifier '_'",
+ );
+
+ cases.add(
+ "`_` should not be usable inside for",
+ \\export fn returns() void {
+ \\ for ([]void{}) |_, i| {
+ \\ for ([]void{}) |_, j| {
+ \\ return _;
+ \\ }
+ \\ }
+ \\}
+ ,
+ ".tmp_source.zig:4:20: error: use of undeclared identifier '_'",
+ );
+
+ cases.add(
+ "`_` should not be usable inside while",
+ \\export fn returns() void {
+ \\ while (optionalReturn()) |_| {
+ \\ while (optionalReturn()) |_| {
+ \\ return _;
+ \\ }
+ \\ }
+ \\}
+ \\fn optionalReturn() ?u32 {
+ \\ return 1;
+ \\}
+ ,
+ ".tmp_source.zig:4:20: error: use of undeclared identifier '_'",
+ );
+
+ cases.add(
+ "`_` should not be usable inside while else",
+ \\export fn returns() void {
+ \\ while (optionalReturnError()) |_| {
+ \\ while (optionalReturnError()) |_| {
+ \\ return;
+ \\ } else |_| {
+ \\ if (_ == error.optionalReturnError) return;
+ \\ }
+ \\ }
+ \\}
+ \\fn optionalReturnError() !?u32 {
+ \\ return error.optionalReturnError;
+ \\}
+ ,
+ ".tmp_source.zig:6:17: error: use of undeclared identifier '_'",
+ );
+
+ cases.add(
"while loop body expression ignored",
\\fn returns() usize {
\\ return 2;