From c60b59e04c3776a90adaa8c8fe53af3075a833b8 Mon Sep 17 00:00:00 2001 From: Mattias EngdegÄrd Date: Fri, 14 Apr 2023 18:26:27 +0200 Subject: Disallow creation of circular variable alias chains Make `defvaralias` signal an error upon attempts to create variable alias cycles. This detects errors earlier and makes the alias traversal during execution simpler and faster since no cycle detection is needed elsewhere. Now variable and function aliases are handled identically in these respects. * src/lisp.h (indirect_variable): Remove declaration. * src/data.c (indirect_variable): Remove. (Findirect_variable): Update doc string. Simplify alias resolution. (Fboundp, find_symbol_value, set_internal, default_value) (set_default_internal, Fmake_variable_buffer_local) (Fmake_local_variable, Fkill_local_variable, Flocal_variable_p) (Flocal_variable_if_set_p, Fvariable_binding_locus): * src/buffer.c (buffer_local_value): * src/eval.c (specbind): Simplify variable alias resolution. (Fdefvaralias): Update doc string. Check for cycles. * doc/lispref/variables.texi (Variable Aliases): Mention that `defvaralias` can signal `cyclic-variable-indirection` but `indirect-variable` cannot. * etc/NEWS: Announce the change. * test/src/eval-tests.el (eval-tests-defvaralias): New test. --- test/src/eval-tests.el | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test') diff --git a/test/src/eval-tests.el b/test/src/eval-tests.el index e0a27439ba2..4589763b2f5 100644 --- a/test/src/eval-tests.el +++ b/test/src/eval-tests.el @@ -266,4 +266,20 @@ expressions works for identifiers starting with period." ) (should (eq eval-test--local-var 'global))) +(ert-deftest eval-tests-defvaralias () + (defvar eval-tests--my-var 'coo) + (defvaralias 'eval-tests--my-var1 'eval-tests--my-var) + (defvar eval-tests--my-var1) + (should (equal eval-tests--my-var 'coo)) + (should (equal eval-tests--my-var1 'coo)) + + (defvaralias 'eval-tests--my-a 'eval-tests--my-b) + (defvaralias 'eval-tests--my-b 'eval-tests--my-c) + + (should-error (defvaralias 'eval-tests--my-c 'eval-tests--my-c) + :type 'cyclic-variable-indirection) + (defvaralias 'eval-tests--my-d 'eval-tests--my-a) + (should-error (defvaralias 'eval-tests--my-c 'eval-tests--my-d) + :type 'cyclic-variable-indirection)) + ;;; eval-tests.el ends here -- cgit v1.2.3