armedbear / abcl

Armed Bear Common Lisp <git+https://github.com/armedbear/abcl/> <--> <svn+https://abcl.org/svn> Bridge
https://abcl.org#rdfs:seeAlso<https://gitlab.common-lisp.net/abcl/abcl>
Other
288 stars 29 forks source link

[clos] update-instance-for-redefined-class is not working correctly #629

Closed alejandrozf closed 10 months ago

alejandrozf commented 10 months ago

I tried the example for the standard generic function UPDATE-INSTANCE-FOR-REDEFINED-CLASS from the hyperspec adding only one instance to reproduce it.

CL-USER(1): (defclass position () ())
#<STANDARD-CLASS POSITION {36AE996}>
CL-USER(2): (defclass x-y-position (position)
     ((x :initform 0 :accessor position-x :initarg :x)
      (y :initform 0 :accessor position-y :initarg :y)))
#<STANDARD-CLASS X-Y-POSITION {1794618C}>
CL-USER(3): (defmethod update-instance-for-redefined-class :before
    ((pos x-y-position) added deleted plist &key)
   ;; Transform the x-y coordinates to polar coordinates
   ;; and store into the new slots.
   (let ((x (getf plist 'x))
         (y (getf plist 'y)))
     (setf (position-rho pos) (sqrt (+ (* x x) (* y y)))
           (position-theta pos) (atan y x))))
#<STANDARD-METHOD UPDATE-INSTANCE-FOR-REDEFINED-CLASS :BEFORE (X-Y-POSITION T T T) {5689919B}>
CL-USER(4): (setf xy1 (make-instance 'x-y-position))
#<X-Y-POSITION {2941EAEE}>
CL-USER(5): (defclass x-y-position (position)
  ((rho :initform 0 :accessor position-rho)
   (theta :initform 0 :accessor position-theta)))
#<STANDARD-CLASS X-Y-POSITION {1794618C}>
CL-USER(6): (slot-value xy1 'rho)
#<THREAD "interpreter" native {5F3F5D78}>: Debugger invoked on condition of type TYPE-ERROR
  The value NIL is not of type NUMBER.
Restarts:
  0: TOP-LEVEL Return to top level.
[1] CL-USER(7):

But I think I'm near to have a fix for this

I'll try to send a PR soon