Skip to content

Commit

Permalink
fix check-statement-is-void. add tests
Browse files Browse the repository at this point in the history
see #291
  • Loading branch information
thejoshwolfe committed Apr 24, 2017
1 parent c6605cb commit ac79711
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion std/debug.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
31 changes: 31 additions & 0 deletions test/compile_errors.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ac79711

Please sign in to comment.