| author | |
| committer | |
| log | 5d99e5ecd493b6cec54cf870d77d61b2a8480131 |
| tree | 7bf897fff1b78788e86b3ab573f049fb762705ce |
| parent | 3d18c8c1300986541bc81d60e81fd702d4417629 |
Closes #44837 files changed, 28 insertions(+), 7 deletions(-)
src/Sema.zig+10-1| ... | ... | @@ -2869,7 +2869,16 @@ fn ensureResultUsed( |
| 2869 | 2869 | }; |
| 2870 | 2870 | return sema.failWithOwnedErrorMsg(block, msg); |
| 2871 | 2871 | }, |
| 2872 | else => return sema.fail(block, src, "expression value is ignored", .{}), | |
| 2872 | else => { | |
| 2873 | const msg = msg: { | |
| 2874 | const msg = try sema.errMsg(block, src, "value of type '{}' ignored", .{operand_ty.fmt(sema.mod)}); | |
| 2875 | errdefer msg.destroy(sema.gpa); | |
| 2876 | try sema.errNote(block, src, msg, "all non-void values must be used", .{}); | |
| 2877 | try sema.errNote(block, src, msg, "this error can be suppressed by assigning the value to '_'", .{}); | |
| 2878 | break :msg msg; | |
| 2879 | }; | |
| 2880 | return sema.failWithOwnedErrorMsg(block, msg); | |
| 2881 | }, | |
| 2873 | 2882 | } |
| 2874 | 2883 | } |
| 2875 | 2884 |
test/cases/compile_errors/ignored_assert-err-ok_return_value.zig+3-1| ... | ... | @@ -7,4 +7,6 @@ fn bar() anyerror!i32 { return 0; } |
| 7 | 7 | // backend=stage2 |
| 8 | 8 | // target=native |
| 9 | 9 | // |
| 10 | // :2:11: error: expression value is ignored | |
| 10 | // :2:11: error: value of type 'i32' ignored | |
| 11 | // :2:11: note: all non-void values must be used | |
| 12 | // :2:11: note: this error can be suppressed by assigning the value to '_' |
test/cases/compile_errors/ignored_comptime_statement_value.zig+3-1| ... | ... | @@ -6,4 +6,6 @@ export fn foo() void { |
| 6 | 6 | // backend=stage2 |
| 7 | 7 | // target=native |
| 8 | 8 | // |
| 9 | // :2:15: error: expression value is ignored | |
| 9 | // :2:15: error: value of type 'comptime_int' ignored | |
| 10 | // :2:15: note: all non-void values must be used | |
| 11 | // :2:15: note: this error can be suppressed by assigning the value to '_' |
test/cases/compile_errors/ignored_comptime_value.zig+3-1| ... | ... | @@ -6,4 +6,6 @@ export fn foo() void { |
| 6 | 6 | // backend=stage2 |
| 7 | 7 | // target=native |
| 8 | 8 | // |
| 9 | // :2:5: error: expression value is ignored | |
| 9 | // :2:5: error: value of type 'comptime_int' ignored | |
| 10 | // :2:5: note: all non-void values must be used | |
| 11 | // :2:5: note: this error can be suppressed by assigning the value to '_' |
test/cases/compile_errors/ignored_deferred_statement_value.zig+3-1| ... | ... | @@ -6,4 +6,6 @@ export fn foo() void { |
| 6 | 6 | // backend=stage2 |
| 7 | 7 | // target=native |
| 8 | 8 | // |
| 9 | // :2:12: error: expression value is ignored | |
| 9 | // :2:12: error: value of type 'comptime_int' ignored | |
| 10 | // :2:12: note: all non-void values must be used | |
| 11 | // :2:12: note: this error can be suppressed by assigning the value to '_' |
test/cases/compile_errors/ignored_return_value.zig+3-1| ... | ... | @@ -7,4 +7,6 @@ fn bar() i32 { return 0; } |
| 7 | 7 | // backend=stage2 |
| 8 | 8 | // target=native |
| 9 | 9 | // |
| 10 | // :2:8: error: expression value is ignored | |
| 10 | // :2:8: error: value of type 'i32' ignored | |
| 11 | // :2:8: note: all non-void values must be used | |
| 12 | // :2:8: note: this error can be suppressed by assigning the value to '_' |
test/cases/compile_errors/ignored_statement_value.zig+3-1| ... | ... | @@ -6,4 +6,6 @@ export fn foo() void { |
| 6 | 6 | // backend=stage2 |
| 7 | 7 | // target=native |
| 8 | 8 | // |
| 9 | // :2:5: error: expression value is ignored | |
| 9 | // :2:5: error: value of type 'comptime_int' ignored | |
| 10 | // :2:5: note: all non-void values must be used | |
| 11 | // :2:5: note: this error can be suppressed by assigning the value to '_' |