Redefining condition can lead to multiple evaluation of initfunctions

Bug #1164969 reported by Jan Moringen
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Fix Released
Undecided
Unassigned

Bug Description

What I do (this is actually the test case from the attached patch):
(defvar bar-counter 0)

(defvar baz-counter 0)

(define-condition condition-with-non-constant-default-initarg ()
  ((bar :initarg :bar
        :reader condition-with-non-constant-default-initarg-bar)
   (baz :initarg :baz
        :reader condition-with-non-constant-default-initarg-baz
        :initform (incf baz-counter)))
  (:default-initargs :bar (incf bar-counter)))
(define-condition condition-with-non-constant-default-initarg ()
  ((bar :initarg :bar
        :reader condition-with-non-constant-default-initarg-bar)
   (baz :initarg :baz
        :reader condition-with-non-constant-default-initarg-baz
        :initform (incf baz-counter)))
  (:default-initargs :bar (incf bar-counter)))

(macrolet ((test (case &body body)
      `(progn
  (setf bar-counter 0
        baz-counter 0)
  (let ((instance (progn ,@body)))
    (assert
     (= 1 (condition-with-non-constant-default-initarg-bar
    instance))
     nil
     ,(format nil "Assertion failed for default initarg initfunction for ~A"
       case))
    (assert
     (= 1 (condition-with-non-constant-default-initarg-baz
    instance))
     nil
     ,(format nil "Assertion failed for slot initfunction for ~A"
       case)))
  (assert (= 1 bar-counter))
  (assert (= 1 baz-counter)))))

  ;; Go through EVAL to avoid optimizations.
  (test :eval+make-condition
    (eval '(make-condition
     'condition-with-non-constant-default-initarg)))
  (test :eval+make-instance
    (eval '(make-instance
     'condition-with-non-constant-default-initarg)))

  ;; Allow optimizations.
  (test :compile+make-condition
    (make-condition
     'condition-with-non-constant-default-initarg))
  (test :compile+make-instance
    (make-instance
     'condition-with-non-constant-default-initarg)))

What happens:
The assertions fail.

What I expected to happen:
All assertions pass.

SBCL version: ~ 1.1.6

Revision history for this message
Jan Moringen (scymtym) wrote :
Changed in sbcl:
status: New → Fix Committed
Changed in sbcl:
status: Fix Committed → Fix Released
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.