From 58087fb9ccb3ebb716256d8f8332c506ebc699ff Mon Sep 17 00:00:00 2001 From: Torben Ewert Date: Sat, 11 Jul 2026 22:12:54 +0200 Subject: [PATCH] test: add failing example of mutual recursion --- test/vm/functions.pi | 20 ++++++++++++++++++++ test/vm/functions.t | 13 +++++++++++++ test/vm/functions_instructions.t | 13 +++++++++++++ 3 files changed, 46 insertions(+) diff --git a/test/vm/functions.pi b/test/vm/functions.pi index 08ddacf..574ce6e 100644 --- a/test/vm/functions.pi +++ b/test/vm/functions.pi @@ -100,3 +100,23 @@ component RecursiveFunction { fact_and_fib(5, 9) } + +component MutuallyRecursiveFunction { + let is_even = fn (i) -> { + if (i == 0) { + true + } else { + is_odd(i - 1) + } + }; + + let is_odd = fn (i) -> { + if (i == 0) { + false + } else { + is_even(i - 1) + } + }; + + is_even(1) +} diff --git a/test/vm/functions.t b/test/vm/functions.t index d02395d..f48ea0a 100644 --- a/test/vm/functions.t +++ b/test/vm/functions.t @@ -26,3 +26,16 @@ $ NO_COLOR="1" print_vm . RecursiveFunction 154 + +# TODO: + $ NO_COLOR="1" print_instructions . MutuallyRecursiveFunction + + ERROR in file ./functions.pi:109:7-13 + + 108 │ } else { + 109 │ is_odd(i - 1) + │ ^^^^^^ + 110 │ } + + Unbound identifier `is_odd` + [1] diff --git a/test/vm/functions_instructions.t b/test/vm/functions_instructions.t index 0c185bf..ceedbf4 100644 --- a/test/vm/functions_instructions.t +++ b/test/vm/functions_instructions.t @@ -314,3 +314,16 @@ 0026 I_Constant 0x0000000A (00000010) 0031 I_Call 2 0036 I_Pop + +# TODO: + $ NO_COLOR="1" print_instructions . MutuallyRecursiveFunction + + ERROR in file ./functions.pi:109:7-13 + + 108 │ } else { + 109 │ is_odd(i - 1) + │ ^^^^^^ + 110 │ } + + Unbound identifier `is_odd` + [1] -- 2.51.2