From ac7971122dc32f59d82430285e7eaefe5d0d4301 Mon Sep 17 00:00:00 2001 From: Josh Wolfe Date: Sun, 23 Apr 2017 21:49:42 -0700 Subject: [PATCH] fix check-statement-is-void. add tests see #291 --- src/ir.cpp | 2 +- std/debug.zig | 2 +- test/compile_errors.zig | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/ir.cpp b/src/ir.cpp index 36d44d14d5..2527fdd803 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -12666,7 +12666,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira static TypeTableEntry *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira, IrInstructionCheckStatementIsVoid *instruction) { - IrInstruction *statement_value = instruction->statement_value; + IrInstruction *statement_value = instruction->statement_value->other; TypeTableEntry *statement_type = statement_value->value.type; if (type_is_invalid(statement_type)) return ira->codegen->builtin_types.entry_invalid; diff --git a/std/debug.zig b/std/debug.zig index 45f7dcf091..b3f6c21e9c 100644 --- a/std/debug.zig +++ b/std/debug.zig @@ -217,7 +217,7 @@ fn getString(st: &ElfStackTrace, offset: u64) -> %[]u8 { fn readAllocBytes(in_stream: &io.InStream, size: usize) -> %[]u8 { const buf = %return global_allocator.alloc(u8, size); %defer global_allocator.free(buf); - if (size < %return in_stream.read(buf)) return error.Eof; + if ((%return in_stream.read(buf)) < size) return error.Eof; return buf; } diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 57e6e54d54..7bde276242 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -1348,6 +1348,37 @@ pub fn addCases(cases: &tests.CompileErrorContext) { \\fn bar() -> i32 { 0 } , ".tmp_source.zig:2:8: error: expression value is ignored"); + cases.add("ignored assert-err-ok return value", + \\export fn foo() { + \\ %%bar(); + \\} + \\fn bar() -> %i32 { 0 } + , ".tmp_source.zig:2:5: error: expression value is ignored"); + + cases.add("ignored statement value", + \\export fn foo() { + \\ 1; + \\} + , ".tmp_source.zig:2:5: error: expression value is ignored"); + + cases.add("ignored comptime statement value", + \\export fn foo() { + \\ comptime {1;} + \\} + , ".tmp_source.zig:2:15: error: expression value is ignored"); + + cases.add("ignored comptime value", + \\export fn foo() { + \\ comptime 1; + \\} + , ".tmp_source.zig:2:5: error: expression value is ignored"); + + cases.add("ignored defered statement value", + \\export fn foo() { + \\ defer {1;} + \\} + , ".tmp_source.zig:2:12: error: expression value is ignored"); + cases.add("integer literal on a non-comptime var", \\export fn foo() { \\ var i = 0;