Steel Bank Common Lisp

Redefining condition can lead to multiple evaluation of initfunctions

Reported by Jan Moringen on 2013-04-05
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
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

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  Edit
Everyone can see this information.

Other bug subscribers