From 2af0204512def6801b49faa432db351a7adaac6d Mon Sep 17 00:00:00 2001
From: Kaz Kylheku <kaz@kylheku.com>
Date: Thu, 29 Dec 2016 13:12:42 -0800
Subject: Bugfix: optarg presence indicators may be specials.

This fixes the incorrect treatment of the x-p parameter in
(lambda (: (x form x-p))) when x-p is a special variable.
It is being lexically bound.

* eval.c (expand_opt_params_rec): When processing a (var
initform) pair, check for (var initform sym). Error out if
sym is not bindable. Check if it is special and if so,
push it into the list of specials.
---
 eval.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/eval.c b/eval.c
index fc3b928f..caac8d83 100644
--- a/eval.c
+++ b/eval.c
@@ -806,6 +806,13 @@ static val expand_opt_params_rec(val params, val menv,
         not_bindable_error(form, sym);
       if (special_var_p(sym))
         push(sym, pspecials);
+      if (cddr(pair)) {
+        val opt_sym = caddr(pair);
+        if (!bindable(opt_sym))
+          not_bindable_error(form, opt_sym);
+        if (special_var_p(opt_sym))
+          push(opt_sym, pspecials);
+      }
       return rlcp(cons(form_ex, expand_opt_params_rec(rest(params), menv,
                                                       form, pspecials)),
                   cdr(params));
-- 
cgit v1.2.3