Destructuring lambda lists are unwarrantedly lax in their treatment of invalid or misplaced lambda list keywords

Bug #708051 reported by Jean-Philippe Paradis on 2011-01-26
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Low
Douglas Katzman

Bug Description

What I do:
1.
(destructuring-bind (&whole &optional test this) '(value)
  (values test this))

2.
(destructuring-bind (a b &keys c) '(va vb)
  a b c)

What happens:
1. &optional is treated just like if it was any other reasonable variable name for &whole.

2. &keys is treated just like if it was any other reasonable variable name for a required argument. (it's obvious the user meant &key. However this pertains to any bogus lambda list keyword, not just small typos)

What I expected to happen:
1. This should be treated as &whole missing its parameter and reported as an error. The behavior should be similar to having &whole or &rest or &body at the end of the list with a missing parameter, but perhaps with a more precise error message such as "Unexpected lambda list keyword &optional found instead of argument to &whole".

2. Symbols beginning with "&" should be treated as "apparent lambda list keywords" and never accepted as variable names. Nobody sane would use such apparent lambda list keywords as variable names. A distinction should be made between actual lambda list keywords (for which (member symbol lambda-list-keywords) => T) and bogus lambda list keywords (for which (member symbol lambda-list-keywords) => NIL) for error detection and error reporting purposes.

SBCL version: 1.0.42
uname -a: Linux dynamorph 2.6.32-27-generic #49-Ubuntu SMP Wed Dec 1 23:52:12 UTC 2010 i686 GNU/Linux

*features*:
(:SWANK :QUICKLISP :SB-BSD-SOCKETS-ADDRINFO :ASDF2 :ASDF :ANSI-CL :COMMON-LISP
 :SBCL :SB-DOC :SB-TEST :SB-LDB :SB-PACKAGE-LOCKS :SB-UNICODE :SB-EVAL
 :SB-SOURCE-LOCATIONS :IEEE-FLOATING-POINT :X86 :UNIX :ELF :LINUX :SB-THREAD
 :LARGEFILE :GENCGC :STACK-GROWS-DOWNWARD-NOT-UPWARD :C-STACK-IS-CONTROL-STACK
 :COMPARE-AND-SWAP-VOPS :UNWIND-TO-FRAME-AND-CALL-VOP :RAW-INSTANCE-INIT-VOPS
 :STACK-ALLOCATABLE-CLOSURES :STACK-ALLOCATABLE-VECTORS
 :STACK-ALLOCATABLE-LISTS :STACK-ALLOCATABLE-FIXED-OBJECTS :ALIEN-CALLBACKS
 :CYCLE-COUNTER :INLINE-CONSTANTS :MEMORY-BARRIER-VOPS :LINKAGE-TABLE
 :OS-PROVIDES-DLOPEN :OS-PROVIDES-PUTWC :OS-PROVIDES-SUSECONDS-T)

Nikodemus Siivola (nikodemus) wrote :

I agree in the main, but not to all details.

&KEYS is a valid variable name -- but since it is likely to be a typo, a style-warning is definitely in order.

Changed in sbcl:
importance: Undecided → Low
status: New → Triaged
Douglas Katzman (dougk) on 2015-06-11
Changed in sbcl:
assignee: nobody → Douglas Katzman (dougk)
Douglas Katzman (dougk) on 2015-07-02
Changed in sbcl:
status: Triaged → Fix Committed
Changed in sbcl:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers