From 72235b0fd4bf7908eb73ab840736e550a7ddd8d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20G=C3=A9lineau?= Date: Fri, 1 Dec 2023 23:39:21 -0500 Subject: [PATCH] lang: ast: New test "clear-env-on-var" This test detects a mistake which is easy to make: when making a recursive call to the target of an ExprVar, it would be easy to accidentally pass the environment, like we usually do with every other recursive call. For variables, this is a mistake, because the lambda parameters which are in scope where the variable is used must not be in scope where the variable is defined. In fact, ExprVar.Graph() currently makes this mistake. The test passes anyway, because an earlier phase (SetScope) correctly clears the environment and detects the problem before the Graph phase. Thus, this test does not guarantee that all the phases correctly clear their environment, it merely detects the unlikely case in which all the phases make the same mistake. --- lang/interpret_test/TestAstFunc2/clear-env-on-var.txtar | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 lang/interpret_test/TestAstFunc2/clear-env-on-var.txtar diff --git a/lang/interpret_test/TestAstFunc2/clear-env-on-var.txtar b/lang/interpret_test/TestAstFunc2/clear-env-on-var.txtar new file mode 100644 index 00000000..1e9ec3ac --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/clear-env-on-var.txtar @@ -0,0 +1,9 @@ +-- main.mcl -- +$wat = $x +$f = func($x) { + $wat +} + +test $f("foo") {} +-- OUTPUT -- +# err: errSetScope: scope-checking the function definition `$f`: failed to set scope on function body: variable x not in scope