Ticket #877 (closed defect: invalid)

Opened 3 years ago

Last modified 3 years ago

sticky default-initargs

Reported by: brooks Owned by:
Priority: normal Milestone:
Component: Compiler Version: 1.6
Keywords: Cc:

Description (last modified by gb) (diff)

Redefining a class does not work properly when the first def contains :default-initargs, but the second def does not. What happens is that use of the second def still has the default initiarg.

? (defclass foo () ((x :accessor x :initarg :x)) (:default-initargs :x 2))

? (describe (make-instance 'foo))

#<FOO #x302093A3C44D>
Class: #<STANDARD-CLASS FOO>
Wrapper: #<CCL::CLASS-WRAPPER FOO #x302093A3E25D>
Instance slots
X: 2

? (defclass foo () ((x :accessor x :initarg :x)))

? (describe (make-instance 'foo))

#<FOO #x302093A3C44D>
Class: #<STANDARD-CLASS FOO>
Wrapper: #<CCL::CLASS-WRAPPER FOO #x302093A3E25D>
Instance slots
X: 2

Change History

comment:1 Changed 3 years ago by gb

  • Status changed from new to closed
  • Resolution set to invalid
  • Description modified (diff)

Note that

? (defclass foo () ((x :accessor x :initarg :x)) (:default-initargs :x 2))
#<STANDARD-CLASS FOO>
? (class-direct-default-initargs (find-class 'foo))
((:X 2 #<Anonymous Function #x3020006148DF>))
? (defclass foo () ((x :accessor x :initarg :x)) (:default-initargs))
#<STANDARD-CLASS FOO>
? (class-direct-default-initargs (find-class 'foo))
NIL

e.g., specifying the :DEFAULT-INITARGS option to DEFCLASS (with a null list of default initargs in this case) changes the class's direct default initargs, not specifying it has no effect when the class object is reinitialized. This is consistent with the MOP's model of class redefinition (where it ultimately involves REINITIALIZE-INSTANCE on the class object using a well-defined set of initargs derived from the expansion of DEFCLASS.

Implementations do differ in their treatment of your example: the versions of LispWorks? and CLISP that I have access to behave as you expect and the versions of SBCL, Allegro, and CCL behave the way that I think is correct. I don't think that CLHS says anything about what happens in this case, but (as I said) I think that what the MOP says is quite clear.

Note: See TracTickets for help on using tickets.