Przeglądaj źródła

Change `deferred_*` scoping behaviour for `if`

gingerBill 6 lat temu
rodzic
commit
19e37c852e
1 zmienionych plików z 4 dodań i 2 usunięć
  1. 4 2
      src/ir.cpp

+ 4 - 2
src/ir.cpp

@@ -8239,7 +8239,8 @@ void ir_build_stmt_internal(irProcedure *proc, Ast *node) {
 
 	case_ast_node(is, IfStmt, node);
 		ir_emit_comment(proc, str_lit("IfStmt"));
-		ir_open_scope(proc); // Open scope here
+		ir_open_scope(proc); // Scope #1
+		defer (ir_close_scope(proc, irDeferExit_Default, nullptr));
 
 		if (is->init != nullptr) {
 			// TODO(bill): Should this have a separate block to begin with?
@@ -8265,7 +8266,6 @@ void ir_build_stmt_internal(irProcedure *proc, Ast *node) {
 		}
 
 		ir_build_stmt(proc, is->body);
-		ir_close_scope(proc, irDeferExit_Default, nullptr);
 
 		ir_emit_jump(proc, done);
 
@@ -8906,6 +8906,8 @@ void ir_end_procedure_body(irProcedure *proc) {
 		ir_emit_unreachable(proc);
 	}
 
+	GB_ASSERT(proc->scope_index == 0);
+
 	proc->curr_block = proc->decl_block;
 	ir_emit_jump(proc, proc->entry_block);
 	proc->curr_block = nullptr;