summaryrefslogtreecommitdiffstats
path: root/tests/012
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-09-15 07:22:50 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-09-15 07:22:50 -0700
commit5c73a495f9563bcccba5a5989f2ae9b50d7280bb (patch)
tree72a56716c0e037f25fc0c72b610de5e50ae53ff7 /tests/012
parent8ca41d8efe17a932e0fe13782021f7430f188568 (diff)
downloadtxr-5c73a495f9563bcccba5a5989f2ae9b50d7280bb.tar.gz
txr-5c73a495f9563bcccba5a5989f2ae9b50d7280bb.tar.bz2
txr-5c73a495f9563bcccba5a5989f2ae9b50d7280bb.zip
compiler: bug: scoping of lambda optionals.
The scoping is not behind handled correctly for optional variables. The init-forms are being evaluated in a scope in which all the variables are already visible, instead of sequentially. Thus, for instance, variable rebinding doesn't work, as in (lambda (: (x x)) ...). When the argument is missing, x ends up with the value : because the expression refers to the new x, rather than the outer x. * stdlib/compiler.tl (compiler comp-lambda-impl): Perform the compilation of the init-forms earlier. Use the same new trick that is used for let*: the target for the code fragment is a locaton obtained from get-loc, which is then attached to a variable afterward. The spec-sub helper is extended with a loc parameter to help with this case. * tests/012/lambda.tl: New test case that fails without this fix.
Diffstat (limited to 'tests/012')
-rw-r--r--tests/012/lambda.tl5
1 files changed, 5 insertions, 0 deletions
diff --git a/tests/012/lambda.tl b/tests/012/lambda.tl
index 96f8ba14..d298f59a 100644
--- a/tests/012/lambda.tl
+++ b/tests/012/lambda.tl
@@ -128,6 +128,11 @@
(test (functionp (lambda (: (n n)))) t)
+(defvarl n)
+
+(ltest
+ [(lambda (: (n n)) n)] nil)
+
(cond
(*compile-test* (exit t))
(t (set *compile-test* t)