(standard-sort-methods si-methods)
(declare (ignore si-primary))
(aver (and (null ii-around) (null si-around)))
- (let ((initargs (ctor-initargs ctor))
- (slot-inits (slot-init-forms ctor (or ii-before si-before))))
+ (let ((initargs (ctor-initargs ctor)))
+ (multiple-value-bind (bindings vars defaulting-initargs body)
+ (slot-init-forms ctor (or ii-before si-before))
(values
- `(let (,@(when (or ii-before ii-after)
- `((.ii-args.
- (list .instance. ,@(quote-plist-keys initargs)))))
- ,@(when (or si-before si-after)
- `((.si-args.
- (list .instance. t ,@(quote-plist-keys initargs))))))
+ `(let ,bindings
+ (declare (ignorable ,@vars))
+ (let (,@(when (or ii-before ii-after)
+ `((.ii-args.
+ (list .instance. ,@(quote-plist-keys initargs) ,@defaulting-initargs))))
+ ,@(when (or si-before si-after)
+ `((.si-args.
+ (list .instance. t ,@(quote-plist-keys initargs) ,@defaulting-initargs)))))
,@(loop for method in ii-before
collect `(invoke-method ,method .ii-args.))
,@(loop for method in si-before
collect `(invoke-method ,method .si-args.))
- ,slot-inits
+ ,@body
,@(loop for method in si-after
collect `(invoke-method ,method .si-args.))
,@(loop for method in ii-after
- collect `(invoke-method ,method .ii-args.)))
- (or ii-before si-before))))))
+ collect `(invoke-method ,method .ii-args.))))
+ (or ii-before si-before)))))))
;;; Return four values from APPLICABLE-METHODS: around methods, before
;;; methods, the applicable primary method, and applicable after
:initial-element nil))
(class-inits ())
(default-inits ())
+ (defaulting-initargs ())
(default-initargs (class-default-initargs class))
(initarg-locations
(compute-initarg-locations
unless (member key initkeys :test #'eq) do
(let* ((type (if (constantp initform) 'constant 'var))
(init (if (eq type 'var) initfn initform)))
+ (ecase type
+ (constant
+ (push key defaulting-initargs)
+ (push initform defaulting-initargs))
+ (var
+ (push key defaulting-initargs)
+ (push (default-init-var-name i) defaulting-initargs)))
(when (eq type 'var)
(let ((init-var (default-init-var-name i)))
(setq init init-var)
collect var into vars
collect `(,var (funcall ,initfn)) into bindings
finally (return (values vars bindings)))
- `(let ,bindings
+ ;; FIXME: adjust comment above!
+ (values bindings vars (nreverse defaulting-initargs)
+ `(,@(delete nil instance-init-forms)
+ ,@class-init-forms)))))))
+#| `(let ,bindings
(declare (ignorable ,@vars))
,@(delete nil instance-init-forms)
- ,@class-init-forms))))))
+ ,@class-init-forms))))))|#
;;; Return an alist of lists (KEY LOCATION ...) telling, for each
;;; key in INITKEYS, which locations the initarg initializes.
(ignore-errors (make-instance 'invalid-default-initargs :foo 1))
(assert (null result))
(assert (typep condition 'program-error)))
+;;; :DEFAULT-INITARGS not passed to INITIALIZE-INSTANCE or
+;;; SHARED-INITIALIZE :BEFORE methods.
+(defclass default-initargs-with-method ()
+ ((foo :initarg :valid-initarg))
+ (:default-initargs :valid-initarg 2))
+(defmethod shared-initialize :before ((thing default-initargs-with-method)
+ slot-names &key valid-initarg)
+ (assert (= valid-initarg 2)))
+(make-instance 'default-initargs-with-method)
+;;; and a test with a non-constant initarg
+(defvar *d-i-w-m-2* 0)
+(defclass default-initargs-with-method2 ()
+ ((foo :initarg :valid-initarg))
+ (:default-initargs :valid-initarg (incf *d-i-w-m-2*)))
+(defmethod shared-initialize :before ((thing default-initargs-with-method2)
+ slot-names &key valid-initarg)
+ (assert (= valid-initarg 1)))
+(make-instance 'default-initargs-with-method2)
+(assert (= *d-i-w-m-2* 1))
\f
;;; from Axel Schairer on cmucl-imp 2004-08-05
(defclass class-with-symbol-initarg ()