Repository: microsoft/regorus (language: python)

Issue:
Else clauses without body are ignored
```
package test

x = 4 {
  false
} else = 5
```
is not evaluated correctly and produces x = Undefined. 


Discussion / hints:

Fix patch:
diff --git a/src/parser.rs b/src/parser.rs
index 1fa5d3b3..6a1c42fe 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -1426,7 +1426,21 @@ impl<'source> Parser<'source> {
                         "expected assignment or query after `else`",
                     ));
                 }
-                _ => break,
+                _ => {
+                    let mut query_span = span.clone();
+                    query_span.end = query_span.start;
+                    let query = Ref::new(Query {
+                        span: query_span,
+                        stmts: vec![],
+                    });
+                    span.end = self.end;
+                    bodies.push(RuleBody {
+                        span,
+                        assign,
+                        query,
+                    });
+                    break;
+                }
             }
         }
         Ok(())


Test patch:
diff --git a/tests/interpreter/cases/rule/else.yaml b/tests/interpreter/cases/rule/else.yaml
new file mode 100644
index 00000000..8d4a7a32
--- /dev/null
+++ b/tests/interpreter/cases/rule/else.yaml
@@ -0,0 +1,18 @@
+# Copyright (c) Microsoft Corporation.
+# Licensed under the MIT License.
+
+cases:
+  - note: else without body
+    data: {}
+    modules:
+      - |
+        package test
+        x = 4 {
+          false
+        } else = 5
+
+        y = 6
+    query: data.test
+    want_result:
+      x: 5
+      y: 6