garage44.eu/jeroen/frits

logclone: git clone https://garage44.eu/jeroen/frits.git

cartopolis-agent · 2026-11-26T13:47:53Z

fix(frits): a bare return may end before a comma or a parenthesis

`_ => return,` in a match arm read the comma as the start of the value to
return and failed with "expected an expression, found `,`". Found porting
Cartopolis's beacon, whose message handler returns early on anything it
does not know.
crates/frits/src/parser.rs |  5 ++++-
 crates/frits/src/tests.rs  | 16 ++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/crates/frits/src/parser.rs b/crates/frits/src/parser.rs
index b48ddc4..aae7109 100644
--- a/crates/frits/src/parser.rs
+++ b/crates/frits/src/parser.rs
@@ -502,7 +502,10 @@ impl Parser {
             }
             Tok::Kw(Kw::Return) => {
                 self.next();
-                let v = if matches!(self.peek(), Tok::Semi | Tok::Sym("}") | Tok::Eof) {
+                let v = if matches!(
+                    self.peek(),
+                    Tok::Semi | Tok::Sym("}") | Tok::Sym(",") | Tok::Sym(")") | Tok::Eof
+                ) {
                     None
                 } else {
                     Some(self.expr()?)
diff --git a/crates/frits/src/tests.rs b/crates/frits/src/tests.rs
index a91f28f..2b8ce4d 100644
--- a/crates/frits/src/tests.rs
+++ b/crates/frits/src/tests.rs
@@ -1012,3 +1012,19 @@ fn more_maths() {
     );
     assert_eq!(out, ["1024 1 2.000 3 5 5"]);
 }
+
+#[test]
+fn a_bare_return_ends_a_match_arm() {
+    let out = said(
+        "script / Out
+        fn f(x: Int) / Out {
+            match x {
+                1 => return,
+                _ => Out.say(\"not one\"),
+            }
+            Out.say(\"after\")
+        }
+        on go() { f(1)\n f(2) }",
+    );
+    assert_eq!(out, ["not one", "after"]);
+}