From 68c6160a14be4e77b98cd704d9e641a03aefa332 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 30 Dec 2022 09:48:30 +0100 Subject: Recursion with max depth --- tests/typ/compiler/recursion.typ | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/typ/compiler/recursion.typ (limited to 'tests/typ/compiler/recursion.typ') diff --git a/tests/typ/compiler/recursion.typ b/tests/typ/compiler/recursion.typ new file mode 100644 index 00000000..ae214631 --- /dev/null +++ b/tests/typ/compiler/recursion.typ @@ -0,0 +1,42 @@ +// Test recursive function calls. +// Ref: false + +--- +// Test with named function. +#let fib(n) = { + if n <= 2 { + 1 + } else { + fib(n - 1) + fib(n - 2) + } +} + +#test(fib(10), 55) + +--- +// Test with unnamed function. +// Error: 17-18 unknown variable +#let f = (n) => f(n - 1) +#f(10) + +--- +// Test capturing with named function. +#let f = 10 +#let f() = f +#test(type(f()), "function") + +--- +// Test capturing with unnamed function. +#let f = 10 +#let f = () => f +#test(type(f()), "integer") + +--- +// Error: 15-21 maximum function call depth exceeded +#let rec(n) = rec(n) + 1 +#rec(1) + +--- +#let f(x) = "hello" +#let f(x) = if x != none { f(none) } else { "world" } +#test(f(1), "world") -- cgit v1.2.3