diff --git a/source/sema.h b/source/sema.h index 609c4abdb..5bcf4324a 100644 --- a/source/sema.h +++ b/source/sema.h @@ -683,6 +683,7 @@ class sema branch(int s, bool r) : start{s}, result{r} { } }; std::vector branches; + bool in_branch = false; stack_entry(int p) : pos{p} { } @@ -695,7 +696,6 @@ class sema } }; std::vector selection_stack; - bool in_branch = false; for ( ; @@ -755,10 +755,10 @@ class sema // Else if we're inside a selection statement but still in the condition // portion (there are no branches entered yet) - else if (std::ssize(selection_stack.back().branches) == 0) { + else if (!selection_stack.back().in_branch) { // If this is a top-level selection statement, handle it the same as // if we weren't an a selection statement - if (std::ssize(selection_stack) == 1) { + if (std::ssize(selection_stack) >= 1) { if (sym.assignment_to) { definite_initializations.push_back( sym.identifier ); } @@ -768,7 +768,6 @@ class sema "local variable " + name + " is used in a condition before it was initialized"); } - return sym.assignment_to; } // Else we can skip the rest of this selection statement, and record // this as the result of the next outer selection statement's current branch @@ -797,7 +796,7 @@ class sema + " is used in a branch before it was initialized"); } - if (!in_branch) { + if (!selection_stack.back().in_branch) { return sym.assignment_to; } @@ -912,11 +911,11 @@ class sema ) { selection_stack.back().branches.emplace_back( pos, false ); - in_branch = true; + selection_stack.back().in_branch = true; } if ( !sym.start ) { - in_branch = false; + selection_stack.back().in_branch = false; } } }