defmethod: make the function known at compile time.
authorStas Boukarev <stassats@gmail.com>
Fri, 1 Nov 2013 11:50:55 +0000 (15:50 +0400)
committerStas Boukarev <stassats@gmail.com>
Fri, 1 Nov 2013 11:50:55 +0000 (15:50 +0400)
(defmethod gf ())
(defun f () (gf))
Produced a warning about an undefined function, even though it would
be implicitly created by defmethod.
Fixes lp#503095.

NEWS
src/pcl/boot.lisp
tests/bug-503095-2.lisp [new file with mode: 0644]
tests/bug-503095.lisp [new file with mode: 0644]
tests/clos.impure.lisp

diff --git a/NEWS b/NEWS
index e514f29..4e427c5 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,8 @@
 ;;;; -*- coding: utf-8; fill-column: 78 -*-
+changes relative to sbcl-1.1.13:
+  * enhancement: Top-level defmethod without defgeneric no longer causes
+    undefined-function warnings in subsequent forms. (lp#503095)
+
 changes in sbcl-1.1.13 relative to sbcl-1.1.12:
   * optimization: better distribution of SXHASH over small conses of related
     values.  (lp#309443)
@@ -21,7 +25,7 @@ changes in sbcl-1.1.13 relative to sbcl-1.1.12:
     from the same location.  (patch by Douglas Katzman, lp#1042405)
   * bug fix: Create vectors of proper internal length when reading literal
     vectors from FASLs. (Reported by Jan Moringen)
-  * bug fix: COMPILE can now succefully compile setf functions.
+  * bug fix: COMPILE can now successfully compile setf functions.
     (Reported by Douglas Katzman)
   * bug fix: run-program performs more correct escaping of arguments on
     Windows. (lp#1239242)
index 2e558ff..b324b84 100644 (file)
@@ -322,6 +322,8 @@ bootstrapping.
   (multiple-value-bind (qualifiers lambda-list body)
       (parse-defmethod args)
     `(progn
+       (eval-when (:compile-toplevel :load-toplevel :execute)
+         (compile-or-load-defgeneric ',name))
       ;; KLUDGE: this double expansion is quite a monumental
       ;; workaround: it comes about because of a fantastic interaction
       ;; between the processing rules of CLHS 3.2.3.1 and the
diff --git a/tests/bug-503095-2.lisp b/tests/bug-503095-2.lisp
new file mode 100644 (file)
index 0000000..f6f3ccb
--- /dev/null
@@ -0,0 +1,5 @@
+(defmethod gf503095-2 ()
+  (gf503095-2))
+
+(defun f503095-2 ()
+  (gf503095-2))
diff --git a/tests/bug-503095.lisp b/tests/bug-503095.lisp
new file mode 100644 (file)
index 0000000..8e4d941
--- /dev/null
@@ -0,0 +1,5 @@
+(defmethod gf503095 ()
+  (gf503095))
+
+(defun f503095 ()
+  (gf503095))
index 7864721..bff25d8 100644 (file)
   ;; DEFMETHOD
   (sb-cltl2:macroexpand-all '(defmethod x (a) (macro))))
 
+(with-test (:name (:defmethod-undefined-function :bug-503095))
+  (flet ((test-load (file)
+           (let (implicit-gf-warning)
+             (handler-bind
+                 ((sb-ext:implicit-generic-function-warning
+                    (lambda (x)
+                      (setf implicit-gf-warning x)
+                      (muffle-warning x)))
+                  ((or warning error) #'error))
+               (load file))
+             (assert implicit-gf-warning))))
+    (multiple-value-bind (fasl warnings errorsp) (compile-file "bug-503095.lisp")
+      (unwind-protect
+           (progn (assert (and fasl (not warnings) (not errorsp)))
+                  (test-load fasl))
+        (and fasl (delete-file fasl))))
+    (test-load "bug-503095-2.lisp")))
 
 ;;;; success