defclass allows invalid slot options

Bug #1887014 reported by Wayne Rittimann, Jr.
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
New
Undecided
Unassigned

Bug Description

CL-USER> (defclass ttt () ((s :initargs (:s))))
#<STANDARD-CLASS COMMON-LISP-USER::TTT>

Note the usage of :initargS instead of :initarg.

CL-USER> (make-instance 'ttt :s 0)
; Debugger entered on #<SB-PCL::INITARG-ERROR {1006F869C3}>

The ANSI standard states that "It is required that all implementations signal an error of type program-error if they observe a class option or slot option that is not implemented locally."

It seems that the slot options are not checked until a call to make-instance for standard-direct-slot-definition. I think any option that is also an :initarg for a slot in that class is erroneously allowed.

 1: ((:METHOD MAKE-INSTANCE (CLASS)) #<STANDARD-CLASS SB-MOP:STANDARD-DIRECT-SLOT-DEFINITION> :CLASS #<STANDARD-CLASS COMMON-LISP-USER::TTT> :NAME S :READERS NIL :WRITERS NIL :INITARGS NIL SB-PCL::SOURCE ..
      Locals:
        CLASS = #<STANDARD-CLASS SB-MOP:STANDARD-DIRECT-SLOT-DEFINITION>
        SB-PCL::INITARGS = (:CLASS #<STANDARD-CLASS COMMON-LISP-USER::TTT> :NAME S :READERS NIL ...)

#<CONS {1007569867}>
--------------------
A proper list:
0: :CLASS
1: #<STANDARD-CLASS COMMON-LISP-USER::TTT>
2: :NAME
3: S
4: :READERS
5: NIL
6: :WRITERS
7: NIL
8: :INITARGS
9: NIL
10: SB-PCL::SOURCE
11: #S(SB-C:DEFINITION-SOURCE-LOCATION :NAMESTRING NIL :INDICES 0)
12: :READERS
13: (S)
14: :INITARGS
15: (:S)

I'll admit to being rather inexperienced with Common Lisp and CLOS. In fact it may be the only reason I noticed this. I mistakenly used :initargs instead of :initarg and it took me a while to figure out why I could not make a new instance.

Environment Info
----------------

$ sbcl --version
SBCL 2.0.6
$ uname -a
Darwin Waynes-MacBook-Pro-2.local 18.7.0 Darwin Kernel Version 18.7.0: Mon Apr 27 20:09:39 PDT 2020; root:xnu-4903.278.35~1/RELEASE_X86_64 x86_64
CL-USER> *FEATURES*
(:SLYNK :CL-JSON-DOUBLE-FLOAT-IS-SUBSUMED :CL-JSON-SINGLE-FLOAT-IS-SUBSUMED
 :CL-JSON-CLOS :CL-JSON :FLEXI-STREAMS :CHUNGA CHIPZ-SYSTEM:GRAY-STREAMS
 :CL-PPCRE :SBCL-DEBUG-PRINT-VARIABLE-ALIST :OSICAT-FD-STREAMS :21BIT-CHARS
 :BORDEAUX-THREADS CFFI-FEATURES:FLAT-NAMESPACE CFFI-FEATURES:X86-64
 CFFI-FEATURES:UNIX CFFI-FEATURES:DARWIN :CFFI CFFI-SYS::FLAT-NAMESPACE
 :SPLIT-SEQUENCE ALEXANDRIA::SEQUENCE-EMPTYP :THREAD-SUPPORT :SWANK :QUICKLISP
 :ASDF3.3 :ASDF3.2 :ASDF3.1 :ASDF3 :ASDF2 :ASDF :OS-MACOSX :OS-UNIX
 :NON-BASE-CHARS-EXIST-P :ASDF-UNICODE :X86-64 :GENCGC :64-BIT :ANSI-CL :BSD
 :COMMON-LISP :DARWIN :IEEE-FLOATING-POINT :LITTLE-ENDIAN :MACH-O
 :PACKAGE-LOCAL-NICKNAMES :SB-CORE-COMPRESSION :SB-LDB :SB-PACKAGE-LOCKS
 :SB-THREAD :SB-UNICODE :SBCL :UNIX)

Tags: pcl
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.