aboutsummaryrefslogtreecommitdiff
path: root/src/check_stmt.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-06-16 12:07:24 +0100
committergingerBill <bill@gingerbill.org>2021-06-16 12:07:24 +0100
commit41f2539484931cd73dfca36dcbdba01e954fc350 (patch)
treea76cd589c96065e2f2becb53004d564b0c6f5ff3 /src/check_stmt.cpp
parent8f57bb07991930f242ec4ab4d9fb3a851a4e9662 (diff)
Improve logic for diverging procedures by checking if it terminates
Diffstat (limited to 'src/check_stmt.cpp')
-rw-r--r--src/check_stmt.cpp23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp
index 4fdece852..24960b33c 100644
--- a/src/check_stmt.cpp
+++ b/src/check_stmt.cpp
@@ -247,11 +247,24 @@ bool check_is_terminating(Ast *node, String const &label) {
case_ast_node(ws, WhenStmt, node);
// TODO(bill): Is this logic correct for when statements?
- if (ws->else_stmt != nullptr) {
- if (check_is_terminating(ws->body, label) &&
- check_is_terminating(ws->else_stmt, label)) {
- return true;
- }
+ auto const &tv = ws->cond->tav;
+ if (tv.mode != Addressing_Constant) {
+ // NOTE(bill): Check the things regardless as a bug occurred earlier
+ if (ws->else_stmt != nullptr) {
+ if (check_is_terminating(ws->body, label) &&
+ check_is_terminating(ws->else_stmt, label)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ if (tv.value.kind == ExactValue_Bool) {
+ if (tv.value.value_bool) {
+ return check_is_terminating(ws->body, label);
+ } else {
+ return check_is_terminating(ws->else_stmt, label);
+ }
}
case_end;