circularity detection of FORMAT NIL behaves oddly in PRINT-OBJECT methods
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
New
|
Undecided
|
Unassigned |
Bug Description
(defclass foo () ())
(defmethod print-object ((o foo) s)
(let ((x "foo"))
(flet ((twice (a s y)
(format s "s ~a ~a~%" x x)
(twice "twice " s x)
(format s "~&nil ~s~%" (format nil "~a ~a" x x))
(twice "twice " s x)
(format s "~&nil ~s~%" (format nil "~a ~a" x x))
(format s "nil/twice ~s~%" (twice "" nil x))
(format s "nil ~s~%" (format nil "~a ~a ~a" "" x x))
(format s "~&wots ~s~%"
(format s "nil ~s~%" (format nil "~a ~a ~a" "" x x))
(format s "wots/twice ~s~%"
(format s "nil ~s~%" (format nil "~a ~a" x x))
(format s "nil/twice ~s~%" (twice "" nil x))
(format s "nil ~s~%" (format nil "~a ~a" x x)))))
(let ((*print-circle* t))
(princ (make-instance 'foo))
(values))
s #1=foo #1#
#2=twice #1# #1#
nil "foo foo"
#2# #1# #1#
nil "foo foo"
nil/twice "#3= #1# #1#"
nil " foo foo"
wots "#3# #1# #1#"
nil "#3# #1# #1#"
wots/twice " #1# #1#"
nil "#1# #1#"
nil/twice "#3# #1# #1#"
nil "#1# #1#"
not completely sure what the correct output is, but (format nil "~a ~a" x x) should probably return either "#1=foo #1#" or "#1# #1#" (or "#1=foo #1#" once then "#1# #1#") depending on whether you consider "creates and returns a string containing the output from control-string" from http://
Either way, returning "#1# #1#" when the NIL isn't a constant, then returning "foo foo" a few times when NIL is passed directly, then "#1# #1#" when NIL is passed directly after calling with-output-
"#1# #1#" shoring up in with-output-
reported by _death on #lisp in context of condition reports (which use print-object) in http:// paste.lisp. org/display/ 330728