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.
This commit is contained in:
9
lang/interpret_test/TestAstFunc2/clear-env-on-var.txtar
Normal file
9
lang/interpret_test/TestAstFunc2/clear-env-on-var.txtar
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user