Subject: bug#3647: 23.1.50; defun* generates incorrect code for handling arglist keyword lookup

From: Lars Magne Ingebrigtsen <[email-masked]>
Date: Sat, 17 Sep 2011 08:19:24 +0200

Miles Bader <[email-masked]> writes:

> Please describe exactly what actions triggered the bug
> and the precise symptoms of the bug:
>
> Given the following code:
>
>    (require 'cl)
>    (defun* oink (&key a b) (list a b))
>
> then evaluating:
>
>    (oink :b :a :a 42)
>    => (:a :a)
>
> ... which is incorrect.  The correct answer is (42 :A).

I can confirm that this bug is still present in Emacs 24.

> Looking at the macro-expansion of the above defun* form, the reason is
> obvious:  the generated code uses (car (cdr (memq KEYWORD ARGLIST))) to
> look up keyword argument values, which is obviously bogus if a preceding
> argument value is the same as a keyword.  It would be more correct to
> use (plist-get ARGUMENT KEYWORD), and that's what common-lisp systems I
> tested return for this test.
>
> However, the code in cl.el that generates keyword handling code is so
> confusing, I'm not really sure how to fix this; presumably something in
> `cl-do-arglist'?

Hm.  I think that function could do with some well-placed comments.  :-)

-- 
(domestic pets only, the antidote for overdose, milk.)
  bloggy blog http://lars.ingebrigtsen.no/