authorgravatar for thejoshwolfe@gmail.comJosh Wolfe <thejoshwolfe@gmail.com> 2017-04-23 22:33:06-07:00
committergravatar for thejoshwolfe@gmail.comJosh Wolfe <thejoshwolfe@gmail.com> 2017-04-23 22:33:06-07:00
log08a871f625aaf75ca47ea6bbc6304587c4bbae86
treea98353f6fa11344883c4b2256d192d3d6daa8ab3
parentac7971122dc32f59d82430285e7eaefe5d0d4301

defer requires expr to be void. closes #341


2 files changed, 24 insertions(+), 13 deletions(-)

src/ir.cpp+17-13
......@@ -2051,6 +2051,18 @@ static IrInstruction *ir_build_check_switch_prongs(IrBuilder *irb, Scope *scope,
20512051 return &instruction->base;
20522052}
20532053
2054static IrInstruction *ir_build_check_statement_is_void(IrBuilder *irb, Scope *scope, AstNode *source_node,
2055 IrInstruction* statement_value)
2056{
2057 IrInstructionCheckStatementIsVoid *instruction = ir_build_instruction<IrInstructionCheckStatementIsVoid>(
2058 irb, scope, source_node);
2059 instruction->statement_value = statement_value;
2060
2061 ir_ref_instruction(statement_value, irb->current_basic_block);
2062
2063 return &instruction->base;
2064}
2065
20542066static IrInstruction *ir_build_test_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
20552067 IrInstruction *type_value, TypeTableEntryId type_id)
20562068{
......@@ -3139,7 +3151,11 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o
31393151 (gen_error_defers && defer_kind == ReturnKindError))
31403152 {
31413153 AstNode *defer_expr_node = defer_node->data.defer.expr;
3142 ir_gen_node(irb, defer_expr_node, defer_node->data.defer.expr_scope);
3154 Scope *defer_expr_scope = defer_node->data.defer.expr_scope;
3155 IrInstruction *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope);
3156 if (defer_expr_value != irb->codegen->invalid_instruction) {
3157 ir_mark_gen(ir_build_check_statement_is_void(irb, defer_expr_scope, defer_expr_node, defer_expr_value));
3158 }
31433159 }
31443160
31453161 }
......@@ -3348,18 +3364,6 @@ static ScopeBlock *find_block_scope(IrExecutable *exec, Scope *scope) {
33483364 return nullptr;
33493365}
33503366
3351static IrInstruction *ir_build_check_statement_is_void(IrBuilder *irb, Scope *scope, AstNode *source_node,
3352 IrInstruction* statement_value)
3353{
3354 IrInstructionCheckStatementIsVoid *instruction = ir_build_instruction<IrInstructionCheckStatementIsVoid>(
3355 irb, scope, source_node);
3356 instruction->statement_value = statement_value;
3357
3358 ir_ref_instruction(statement_value, irb->current_basic_block);
3359
3360 return &instruction->base;
3361}
3362
33633367static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode *block_node) {
33643368 assert(block_node->type == NodeTypeBlock);
33653369
test/compile_errors.zig+7
......@@ -1379,6 +1379,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
13791379 \\}
13801380 , ".tmp_source.zig:2:12: error: expression value is ignored");
13811381
1382 cases.add("ignored defered statement value",
1383 \\export fn foo() {
1384 \\ defer bar();
1385 \\}
1386 \\fn bar() -> %i32 { 0 }
1387 , ".tmp_source.zig:2:14: error: expression value is ignored");
1388
13821389 cases.add("integer literal on a non-comptime var",
13831390 \\export fn foo() {
13841391 \\ var i = 0;