AstGen: check loop bodies and else branches for unused result
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
fn returns() usize {
|
||||
return 2;
|
||||
}
|
||||
export fn f1() void {
|
||||
for ("hello") |_| returns();
|
||||
}
|
||||
export fn f2() void {
|
||||
var x: anyerror!i32 = error.Bad;
|
||||
for ("hello") |_| returns() else unreachable;
|
||||
_ = x;
|
||||
}
|
||||
export fn f3() void {
|
||||
for ("hello") |_| {} else true;
|
||||
}
|
||||
export fn f4() void {
|
||||
const foo = for ("hello") |_| returns() else true;
|
||||
_ = foo;
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :5:30: error: value of type 'usize' ignored
|
||||
// :5:30: note: all non-void values must be used
|
||||
// :5:30: note: this error can be suppressed by assigning the value to '_'
|
||||
// :9:30: error: value of type 'usize' ignored
|
||||
// :9:30: note: all non-void values must be used
|
||||
// :9:30: note: this error can be suppressed by assigning the value to '_'
|
||||
// :13:31: error: value of type 'bool' ignored
|
||||
// :13:31: note: all non-void values must be used
|
||||
// :13:31: note: this error can be suppressed by assigning the value to '_'
|
||||
// :16:42: error: value of type 'usize' ignored
|
||||
// :16:42: note: all non-void values must be used
|
||||
// :16:42: note: this error can be suppressed by assigning the value to '_'
|
||||
@@ -1,18 +0,0 @@
|
||||
fn returns() usize {
|
||||
return 2;
|
||||
}
|
||||
export fn f1() void {
|
||||
for ("hello") |_| returns();
|
||||
}
|
||||
export fn f2() void {
|
||||
var x: anyerror!i32 = error.Bad;
|
||||
for ("hello") |_| returns() else unreachable;
|
||||
_ = x;
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:5:30: error: expression value is ignored
|
||||
// tmp.zig:9:30: error: expression value is ignored
|
||||
@@ -1,22 +0,0 @@
|
||||
fn returns() usize {
|
||||
return 2;
|
||||
}
|
||||
export fn f1() void {
|
||||
while (true) returns();
|
||||
}
|
||||
export fn f2() void {
|
||||
var x: ?i32 = null;
|
||||
while (x) |_| returns();
|
||||
}
|
||||
export fn f3() void {
|
||||
var x: anyerror!i32 = error.Bad;
|
||||
while (x) |_| returns() else |_| unreachable;
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage1
|
||||
// target=native
|
||||
//
|
||||
// tmp.zig:5:25: error: expression value is ignored
|
||||
// tmp.zig:9:26: error: expression value is ignored
|
||||
// tmp.zig:13:26: error: expression value is ignored
|
||||
@@ -0,0 +1,43 @@
|
||||
fn returns() usize {
|
||||
return 2;
|
||||
}
|
||||
export fn f1() void {
|
||||
while (true) returns();
|
||||
}
|
||||
export fn f2() void {
|
||||
var x: ?i32 = null;
|
||||
while (x) |_| returns();
|
||||
}
|
||||
export fn f3() void {
|
||||
var x: anyerror!i32 = error.Bad;
|
||||
while (x) |_| returns() else |_| unreachable;
|
||||
}
|
||||
export fn f4() void {
|
||||
var a = true;
|
||||
while (a) {} else true;
|
||||
}
|
||||
export fn f5() void {
|
||||
var a = true;
|
||||
const foo = while (a) returns() else true;
|
||||
_ = foo;
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :5:25: error: value of type 'usize' ignored
|
||||
// :5:25: note: all non-void values must be used
|
||||
// :5:25: note: this error can be suppressed by assigning the value to '_'
|
||||
// :9:26: error: value of type 'usize' ignored
|
||||
// :9:26: note: all non-void values must be used
|
||||
// :9:26: note: this error can be suppressed by assigning the value to '_'
|
||||
// :13:26: error: value of type 'usize' ignored
|
||||
// :13:26: note: all non-void values must be used
|
||||
// :13:26: note: this error can be suppressed by assigning the value to '_'
|
||||
// :17:23: error: value of type 'bool' ignored
|
||||
// :17:23: note: all non-void values must be used
|
||||
// :17:23: note: this error can be suppressed by assigning the value to '_'
|
||||
// :21:34: error: value of type 'usize' ignored
|
||||
// :21:34: note: all non-void values must be used
|
||||
// :21:34: note: this error can be suppressed by assigning the value to '_'
|
||||
Reference in New Issue
Block a user