remove redundant unreachable code error

This commit is contained in:
Josh Wolfe 2017-04-23 08:34:18 -07:00
parent 8299fe19c0
commit 14dfbd6ad3
2 changed files with 2 additions and 11 deletions

View File

@ -3387,15 +3387,6 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
continue; continue;
} }
if (is_continuation_unreachable) {
// if you put a semicolon after a return statement,
// then we get a void statement in the unreachable area.
// this is fine. ignore any void blocks we get from this happening.
if (statement_node->type == NodeTypeBlock && statement_node->data.block.statements.length == 0)
continue;
add_node_error(irb->codegen, statement_node, buf_sprintf("unreachable code"));
}
IrInstruction *statement_value = ir_gen_node(irb, statement_node, child_scope); IrInstruction *statement_value = ir_gen_node(irb, statement_node, child_scope);
is_continuation_unreachable = instr_is_unreachable(statement_value); is_continuation_unreachable = instr_is_unreachable(statement_value);
if (is_continuation_unreachable) if (is_continuation_unreachable)
@ -3411,7 +3402,7 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
IrInstructionDeclVar *decl_var_instruction = (IrInstructionDeclVar *)statement_value; IrInstructionDeclVar *decl_var_instruction = (IrInstructionDeclVar *)statement_value;
child_scope = decl_var_instruction->var->child_scope; child_scope = decl_var_instruction->var->child_scope;
} else { } else {
// label, defer, variable declaration will never be the last statement // label, defer, variable declaration will never be the result expression
if (block_node->data.block.last_statement_is_result_expression && if (block_node->data.block.last_statement_is_result_expression &&
i == block_node->data.block.statements.length - 1) { i == block_node->data.block.statements.length - 1) {
// this is the result value statement // this is the result value statement

View File

@ -254,7 +254,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\} \\}
\\ \\
\\fn b() {} \\fn b() {}
, ".tmp_source.zig:3:6: error: unreachable code"); , ".tmp_source.zig:3:5: error: unreachable code");
cases.add("bad import", cases.add("bad import",
\\const bogus = @import("bogus-does-not-exist.zig"); \\const bogus = @import("bogus-does-not-exist.zig");