From 5728601f88c400d2992b6b8c70d8971d07de9029 Mon Sep 17 00:00:00 2001 From: Stas Boukarev Date: Fri, 1 Nov 2013 15:50:55 +0400 Subject: [PATCH] defmethod: make the function known at compile time. (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 | 6 +++++- src/pcl/boot.lisp | 2 ++ tests/bug-503095-2.lisp | 5 +++++ tests/bug-503095.lisp | 5 +++++ tests/clos.impure.lisp | 17 +++++++++++++++++ 5 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/bug-503095-2.lisp create mode 100644 tests/bug-503095.lisp diff --git a/NEWS b/NEWS index e514f29..4e427c5 100644 --- 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) diff --git a/src/pcl/boot.lisp b/src/pcl/boot.lisp index 2e558ff..b324b84 100644 --- a/src/pcl/boot.lisp +++ b/src/pcl/boot.lisp @@ -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 index 0000000..f6f3ccb --- /dev/null +++ b/tests/bug-503095-2.lisp @@ -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 index 0000000..8e4d941 --- /dev/null +++ b/tests/bug-503095.lisp @@ -0,0 +1,5 @@ +(defmethod gf503095 () + (gf503095)) + +(defun f503095 () + (gf503095)) diff --git a/tests/clos.impure.lisp b/tests/clos.impure.lisp index 7864721..bff25d8 100644 --- a/tests/clos.impure.lisp +++ b/tests/clos.impure.lisp @@ -2101,5 +2101,22 @@ ;; 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 -- 1.7.10.4