From 13f80fdf95617d662218007fb5a2025caacdaf41 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 12 Jan 2022 17:57:19 -0600 Subject: [PATCH] Bugfix: More cases where if/else is not working as intended. In the previous commit I accidentally removed the "or" condition. I also found that I needed to be more thorough with the logic. The condition result needs to be returned and handled when immediately returning. This then allows for subsequent conditions to use the condition result. The condition result gets reset on each pass of the loop. The block result needs to then retrieve the condition result to ensure the result is preserved across loop passes. --- level_3/fake/c/private-make-operate.c | 3 ++ level_3/fake/c/private-make-operate_process.c | 41 ++++++++++++++++++++------- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/level_3/fake/c/private-make-operate.c b/level_3/fake/c/private-make-operate.c index f96d8be..712446b 100644 --- a/level_3/fake/c/private-make-operate.c +++ b/level_3/fake/c/private-make-operate.c @@ -1391,6 +1391,9 @@ extern "C" { state_process.block_result = fake_condition_result_false_e; success_block = F_false; } + else { + state_process.block_result = state_process.condition_result; + } } else { if (state_process.block == fake_state_process_block_if_skip_e || state_process.block == fake_state_process_block_skip_e) { diff --git a/level_3/fake/c/private-make-operate_process.c b/level_3/fake/c/private-make-operate_process.c index 3fd1357..9dd755f 100644 --- a/level_3/fake/c/private-make-operate_process.c +++ b/level_3/fake/c/private-make-operate_process.c @@ -21,18 +21,37 @@ extern "C" { if (state_process->block) { if (state_process->block == fake_state_process_block_if_e) { - if (state_process->block_result == fake_condition_result_false_e) { - return 0; + if (state_process->operation == fake_make_operation_type_or_e) { + + // For cases of "or", if the previous condition is true, then don't bother because "true || X" is always true. + if (state_process->block_result == fake_condition_result_true_e) { + state_process->condition_result = state_process->block_result; + + return 0; + } + } + else { + + // For all other cases, if the previous condition is false, then it is always false because "false && XX" is always false. + if (state_process->block_result == fake_condition_result_false_e) { + state_process->condition_result = state_process->block_result; + + return 0; + } } } else if (state_process->block == fake_state_process_block_if_skip_e) { if (!(state_process->operation == fake_make_operation_type_and_e || state_process->operation == fake_make_operation_type_or_e)) { + state_process->condition_result = state_process->block_result; + return 0; } } else if (state_process->block == fake_state_process_block_else_e) { if (state_process->operation != fake_make_operation_type_if_e) { if (state_process->block_result == fake_condition_result_false_e) { + state_process->condition_result = state_process->block_result; + return 0; } } @@ -314,16 +333,16 @@ extern "C" { return 0; } - if (state_process->operation == fake_make_operation_type_or_e) { - if (state_process->block_result == fake_condition_result_true_e || state_process->condition_result == fake_condition_result_true_e) { - state_process->condition_result = fake_condition_result_true_e; - } - else { - state_process->condition_result = fake_condition_result_false_e; + if (state_process->block) { + if (state_process->operation == fake_make_operation_type_or_e) { + if (state_process->block_result == fake_condition_result_true_e || state_process->condition_result == fake_condition_result_true_e) { + state_process->condition_result = fake_condition_result_true_e; + } + else { + state_process->condition_result = fake_condition_result_false_e; + } } - } - else if (state_process->block) { - if (state_process->block_result == fake_condition_result_true_e && state_process->condition_result == fake_condition_result_true_e) { + else if (state_process->block_result == fake_condition_result_true_e && state_process->condition_result == fake_condition_result_true_e) { state_process->condition_result = fake_condition_result_true_e; } else { -- 1.8.3.1