Clozure / ccl

Clozure Common Lisp
http://ccl.clozure.com
Apache License 2.0
855 stars 103 forks source link

method class not working #357

Open Slids opened 3 years ago

Slids commented 3 years ago

Trying to call:

(DEFGENERIC AT-RESTART                                                                                                                        
            NIL                                                                                                                                        
            (:DOCUMENTATION "Methods called when the image is restarted.")                                                                             
            (:METHOD-CLASS t)                                                                                                                          
            (:METHOD foo NIL T))

at the repl gives: While compiling (AT-RESTART (T T)) :
Can't bind or assign to constant :METHOD-CLASS.

The hyperspec has it: http://clhs.lisp.se/Body/m_defgen.htm

svspire commented 3 years ago

There are at least two bugs here. First, there's a bug in your code (t is not a valid method class) and second, there seems to be a bug in CCL.

Let's fix the first one first:

(DEFGENERIC AT-RESTART                                                                                                                        
            NIL                                                                                                                                        
            (:DOCUMENTATION "Methods called when the image is restarted.")                                                                             
            (:METHOD-CLASS standard-method)                                                                                                                          
            (:METHOD foo NIL T))

Also foo is not a valid method qualifier but I assume you know that.

The more serious problem seems to be this clause in CCL's definition of #'parse-defgeneric:

(when method-class
      (dolist (m methods)
        (push `(:method-class ,method-class) (cddr m))))

I don't know what that code is doing there and it makes no sense to me. Might be a holdover from the pre-MOP MCL days. It does make sense that it's an old bug since :method-class is a seldom-used option. If that entire clause is removed from #'parse-defgeneric, the error goes away.

Comments or ideas RME?

Slids commented 3 years ago

Sorry for the first bug. For context, we're using it: https://github.com/cybersurf/ace.core/blob/master/hook.lisp with hook functions.

mathrick commented 2 years ago

Running into this as well. Minimal reproducible example (doesn't need anything except standard method combination):

(defgeneric test-gf (foo bar)
  (:method-class standard-method)
  (:method :around (foo bar) 
    "This should work"))