Fix (documentation #'function t)
authorStas Boukarev <stassats@gmail.com>
Mon, 4 Feb 2013 11:21:22 +0000 (15:21 +0400)
committerStas Boukarev <stassats@gmail.com>
Mon, 4 Feb 2013 11:21:22 +0000 (15:21 +0400)
(defun test () "xx" nil)
(setf (documentation 'test 'function) "test")
(list (documentation #'test t) (documentation 'test 'function)))
returned ("xx" "test").

NEWS
src/pcl/documentation.lisp
tests/interface.impure.lisp

diff --git a/NEWS b/NEWS
index e0fea8f..2ac0eb7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -23,13 +23,16 @@ changes relative to sbcl-1.1.4:
        SB-DEBUG:BACKTRACE-AS-LIST.
     ** SB-DEBUG:*SHOW-ENTRY-POINT-DETAILS** has been deprecated, as the same
        information is available in less intrusive form as frame annotations.
-  * enhancement: SB-POSIX now supports provides MAP-ANON.
+  * enhancement: SB-POSIX now provides MAP-ANON.
   * bug fix: no more unused variable style warnings from RESTART-CASE
     macroexpansion (lp#1113859)
   * bug fix: deleting a package removes it from implementation-package
     lists of other packages.
   * bug fix: SB-SPROF:WITH-PROFILING is now usable in the Slime REPL on Darwin.
     This does not fix the occasional "interrupt already pending" issue, though.
+  * bug fix: (setf (documentation 'x 'function)) and
+    (setf (documentation #'x t)) set documentation in different places.
+    (regression since 1.0.43.63)
 
 changes in sbcl-1.1.4 relative to sbcl-1.1.3:
   * optimization: LOOP expressions using "of-type character" have slightly
index e992894..7521653 100644 (file)
       (setf (slot-value x '%documentation) new-value)
       (setf (%fun-doc x) new-value)))
 
+(defun real-function-name (name)
+  ;; Resolve the actual name of the function named by NAME
+  ;; e.g. (setf (name-function 'x) #'car)
+  ;; (real-function-name 'x) => CAR
+  (cond ((not (fboundp name))
+         nil)
+        ((and (symbolp name)
+              (special-operator-p name))
+         (%fun-name (fdefinition name)))
+        ((and (symbolp name)
+              (macro-function name))
+         (let ((name (%fun-name (macro-function name))))
+           (and (consp name)
+                (eq (car name) 'macro-function)
+                (cadr name))))
+        (t
+         (sb-impl::fun-name (fdefinition name)))))
+
+(defun set-function-name-documentation (name documentation)
+  (cond ((not (legal-fun-name-p name))
+         nil)
+        ((not (equal (real-function-name name) name))
+         (setf (random-documentation name 'function) documentation))
+        (t
+         (setf (fun-doc (or (and (symbolp name)
+                                 (macro-function name))
+                            (fdefinition name)))
+               documentation))))
+
 ;;; functions, macros, and special forms
 (defmethod documentation ((x function) (doc-type (eql 't)))
   (fun-doc x))
   (setf (fun-doc x) new-value))
 
 (defmethod (setf documentation) (new-value (x list) (doc-type (eql 'function)))
-  (when (legal-fun-name-p x)
-    (setf (random-documentation x 'function) new-value)))
+  (set-function-name-documentation x new-value))
 
 (defmethod (setf documentation) (new-value (x list) (doc-type (eql 'compiler-macro)))
   (awhen (compiler-macro-function x)
     (setf (documentation it t) new-value)))
 
 (defmethod (setf documentation) (new-value (x symbol) (doc-type (eql 'function)))
-  (when (legal-fun-name-p x)
-    (setf (random-documentation x 'function) new-value)))
+  (set-function-name-documentation x new-value))
 
 (defmethod (setf documentation) (new-value (x symbol) (doc-type (eql 'compiler-macro)))
   (awhen (compiler-macro-function x)
index 31cb517..4391278 100644 (file)
   (assert
    (or (member :big-endian *features*)
        (member :little-endian *features*))))
+
+(with-test (:name :function-documentation-mismatch)
+  (defun test ()
+    "X"
+    nil)
+  (setf (symbol-function 'test2) #'test)
+  (setf (documentation 'test 'function) "Y")
+  (assert (equal (documentation #'test t)
+                 (documentation 'test 'function)))
+  (setf (documentation 'test2 'function) "Z")
+  (assert (not
+           (equal (documentation 'test 'function)
+                  (documentation 'test2 'function)))))
+
+
 \f
 ;;;; success