From 74568641cd71e1628749d583a3f1fdba08fc9a48 Mon Sep 17 00:00:00 2001 From: Kris Katterjohn Date: Tue, 27 Jun 2017 18:42:20 -0500 Subject: [PATCH] No longer allow LET/LET* to bind constants in bytecode compiler/interpreter LET/LET* were allowed to lexically and dynamically bind constants in the bytecode compiler and interpreter: > (let ((pi 3)) pi) 3 > (progn (defconstant +c+ 'foo) (let ((+c+ 'bar)) +c+)) BAR > (flet ((hello () (format t "hi"))) (let ((t nil)) (declare (special t)) ; Oops, now this returns a string (hello))) "hi" Plus plenty of other ways to wreak havoc on unsuspecting code. CLHS says the behavior is undefined when attempting to bind or assign constant variables (CLHS 3.1.2.1.1.3 and the entry for defconstant). (Well, CLHS 3.4.1 explicitly says that constant variables cannot be used for variables in lambda lists.) The C-compiler gives errors for these sorts of things, and the bytecode compiler and interpreter gives errors when attempting to bind or assign constant variables in lambda expressions, SETQ and various other forms. So the behavior above in LET is inconsistent with both the C-compiler and other parts of the bytecode compiler and interpreter. Now give an error when attempting to bind a constant variable in LET/LET* in the bytecode compiler and interpreter. This also changes the behavior of PROG/PROG* and DESTRUCTURING-BIND so that they give errors when attempting to bind constants as well. --- src/c/compiler.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/c/compiler.d b/src/c/compiler.d index b5ee4df47..23fba03c9 100644 --- a/src/c/compiler.d +++ b/src/c/compiler.d @@ -1566,7 +1566,7 @@ c_let_leta(cl_env_ptr env, int op, cl_object args, int flags) { if (!Null(aux)) FEprogram_error_noreturn("LET: Ill formed declaration.",0); } - if (!ECL_SYMBOLP(var)) + if (!ECL_SYMBOLP(var) || (ecl_symbol_type(var) & ecl_stp_constant)) FEillegal_variable_name(var); if (op == OP_PBIND) { compile_form(env, value, FLAG_PUSH);