authorgravatar for thejoshwolfe@gmail.comJosh Wolfe <thejoshwolfe@gmail.com> 2017-04-23 21:49:42-07:00
committergravatar for thejoshwolfe@gmail.comJosh Wolfe <thejoshwolfe@gmail.com> 2017-04-23 21:50:34-07:00
logac7971122dc32f59d82430285e7eaefe5d0d4301
tree191b797a0b54b9832711dc76e88d98d460546291
parentc6605cba8375871a145896f9cf1090e9c823214a

fix check-statement-is-void. add tests

see #291

3 files changed, 33 insertions(+), 2 deletions(-)

src/ir.cpp+1-1
......@@ -12666,7 +12666,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
1266612666static 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+1-1
......@@ -217,7 +217,7 @@ fn getString(st: &ElfStackTrace, offset: u64) -> %[]u8 {
217217fn 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+31
......@@ -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;