Skip to content

Commit ac79711

Browse files
committed
fix check-statement-is-void. add tests
see #291
1 parent c6605cb commit ac79711

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

src/ir.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12666,7 +12666,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
1266612666
static TypeTableEntry *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira,
1266712667
IrInstructionCheckStatementIsVoid *instruction)
1266812668
{
12669-
IrInstruction *statement_value = instruction->statement_value;
12669+
IrInstruction *statement_value = instruction->statement_value->other;
1267012670
TypeTableEntry *statement_type = statement_value->value.type;
1267112671
if (type_is_invalid(statement_type))
1267212672
return ira->codegen->builtin_types.entry_invalid;

std/debug.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ fn getString(st: &ElfStackTrace, offset: u64) -> %[]u8 {
217217
fn readAllocBytes(in_stream: &io.InStream, size: usize) -> %[]u8 {
218218
const buf = %return global_allocator.alloc(u8, size);
219219
%defer global_allocator.free(buf);
220-
if (size < %return in_stream.read(buf)) return error.Eof;
220+
if ((%return in_stream.read(buf)) < size) return error.Eof;
221221
return buf;
222222
}
223223

test/compile_errors.zig

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,37 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
13481348
\\fn bar() -> i32 { 0 }
13491349
, ".tmp_source.zig:2:8: error: expression value is ignored");
13501350

1351+
cases.add("ignored assert-err-ok return value",
1352+
\\export fn foo() {
1353+
\\ %%bar();
1354+
\\}
1355+
\\fn bar() -> %i32 { 0 }
1356+
, ".tmp_source.zig:2:5: error: expression value is ignored");
1357+
1358+
cases.add("ignored statement value",
1359+
\\export fn foo() {
1360+
\\ 1;
1361+
\\}
1362+
, ".tmp_source.zig:2:5: error: expression value is ignored");
1363+
1364+
cases.add("ignored comptime statement value",
1365+
\\export fn foo() {
1366+
\\ comptime {1;}
1367+
\\}
1368+
, ".tmp_source.zig:2:15: error: expression value is ignored");
1369+
1370+
cases.add("ignored comptime value",
1371+
\\export fn foo() {
1372+
\\ comptime 1;
1373+
\\}
1374+
, ".tmp_source.zig:2:5: error: expression value is ignored");
1375+
1376+
cases.add("ignored defered statement value",
1377+
\\export fn foo() {
1378+
\\ defer {1;}
1379+
\\}
1380+
, ".tmp_source.zig:2:12: error: expression value is ignored");
1381+
13511382
cases.add("integer literal on a non-comptime var",
13521383
\\export fn foo() {
13531384
\\ var i = 0;

0 commit comments

Comments
 (0)