]> Kevux Git Server - fll/commitdiff
Bugfix: More cases where if/else is not working as intended.
authorKevin Day <thekevinday@gmail.com>
Wed, 12 Jan 2022 23:57:19 +0000 (17:57 -0600)
committerKevin Day <thekevinday@gmail.com>
Wed, 12 Jan 2022 23:57:19 +0000 (17:57 -0600)
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
level_3/fake/c/private-make-operate_process.c

index f96d8bed1dde3aecf9ecbf16ce51e7aebd4d8292..712446b51794c4905180e0b56f207a798debe11a 100644 (file)
@@ -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) {
index 3fd1357c6720cddc5e96bc91daefc80492f0c34d..9dd755f73b4c128d0221f09b29ad3ae89c4f59d0 100644 (file)
@@ -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 {