summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Bernoulli <jonas@bernoul.li>2024-10-03 21:06:11 +0200
committerJonas Bernoulli <jonas@bernoul.li>2024-10-04 22:58:44 +0200
commit089cf6f80f4e5c89e5b014b431a4d103dee3c219 (patch)
tree999bc246baeca3fc3204bde69dbcd2634c30f683
parenta286543c01ebe3735611b125c01baaca2b9b5218 (diff)
Add note about opaqueness of macros' argument handling
Add that in form of a commented test. Basically, we cannot know what macros do with their arguments. One might of course argue that we should add special handling for `setq', `setq-local' and `setq-default'. But where to stop? What about `setf'? And what about external macros such as `-setq'? It is probably best to stop before even entering the special case lane at all.
-rw-r--r--llama-test.el40
1 files changed, 40 insertions, 0 deletions
diff --git a/llama-test.el b/llama-test.el
index 8f20076..534997e 100644
--- a/llama-test.el
+++ b/llama-test.el
@@ -431,6 +431,46 @@
(should-error (##list %1 %1 &1))
)
+(ert-deftest llama-test-801-ambiguity nil
+
+ ;; We cannot know how every special form and macro uses its arguments,
+ ;; and can therefore not always do the right thing™. However, whatever
+ ;; we end up doing, font-lock should agree. Here are some noteworthy
+ ;; examples where our macro expansion and our font-lock agree, but the
+ ;; author might have intended something else.
+
+ (with-no-warnings ; unused arguments
+
+ ;; A good example of what we might not want and theoretically could
+ ;; prevent. However, this can also be prevented by just not going
+ ;; out of our way to wander into ambigious territory. While not
+ ;; impossible, it is unlikely that someone does this accidentally.
+ (should (equal (##setq % 1)
+ (lambda (%)
+ (setq % 1))))
+
+ ;; We have to fake `-setq' because we don't want to depend on `dash'
+ ;; and because (equal (lambda () (-setq a 1)) (lambda () (-setq a 1)))
+ ;; is never true because `-setq' uses `make-symbol'. Mocking that
+ ;; macro does *not* affect the expansion of `##' into a `lambda'.
+ (cl-macrolet ((-setq (&rest args) `'(,@args)))
+ (should (equal (##-setq % 1)
+ (lambda (%)
+ (-setq % 1))))
+ (should (equal (##-setq (%) '(1))
+ (lambda ()
+ (-setq (%) '(1)))))
+ (should (equal (##-setq [(%)] [(1)])
+ (lambda ()
+ (-setq [(%)] [(1)]))))
+ (should (equal (##-setq [(% %)] [(1 2)])
+ (lambda (%)
+ (-setq [(% %)] [(1 2)]))))
+ (should (equal (##-setq [(%1)] [(1)])
+ (lambda (%1)
+ (-setq [(%1)] [(1)]))))))
+ )
+
(ert-deftest llama-test-902-errors-second nil
(should-error (##list %2 &2))
(should-error (##list &2 %2))