From: James Y Knight <foom@fu...> - 2006-12-06 16:16:55
Originally reported to me by Mark Nahabedian.
Put this in a file:
> (in-package :cl-user)
> (defclass foo ()
> ((foo1) (foo2)))
> (defmacro foobie-doo (&environment env class-name)
> (let ((class (find-class class-name t env)))
> (print (foobie-doo foo))
> (compile-file "sbcl-defclass-bug.lisp")
> ; in: FOOBIE-DOO FOO
> ; (FOOBIE-DOO FOO)
> ; caught ERROR:
> ; (during macroexpansion of (FOOBIE-DOO FOO))
> ; There is no class named FOO.
> ; compilation unit finished
> ; caught 1 ERROR condition
> But the CommonLisp spec (see "Macro DEFCLASS")
> If a defclass form appears as a top level form, the compiler
> must make
> the class name be recognized as a valid type name in subsequent
> declarations (as for deftype) and be recognized as a valid
> class name
> for defmethod parameter specializers and for use as the :metaclass
> option of a subsequent defclass. The compiler must make the class
> definition available to be returned by find-class when its
> argument is a value received as the environment parameter of a
Wrapping the defclass in (eval-when (:compile-toplevel :load-
toplevel :execute) ..) is a trivial workaround.
From: Tim Bradshaw <tfb@tf...> - 2006-12-07 08:35:22
On 6 Dec 2006, at 16:16, James Y Knight wrote:
> Wrapping the defclass in (eval-when (:compile-toplevel :load-
> toplevel :execute) ..) is a trivial workaround.
It's a long time since I looked at the spec on this (I meant to last
night, but ran out of time), but I think this would probably be a bad
solution. I think you need to *not* have a class definition in a
compilation unit cause that class to become defined outside it, but
merely to be defined (or look as if it is defined) within it. This
is the same as for function definitions, etc.