class-prototype for built-in classes

Bug #458164 reported by Levente Mészáros on 2009-10-22
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Medium
Unassigned

Bug Description

CL-USER> (typep (sb-pcl:class-prototype (find-class 'list)) 'list)
NIL
CL-USER> (typep (sb-pcl:class-prototype (find-class 'string)) 'string)
NIL
CL-USER> (typep (sb-pcl:class-prototype (find-class 'float)) 'float)
NIL

Attila Lendvai (attila-lendvai) wrote :

as discussed on #lisp, it would be wrong to put, let's say a NIL in the class-prototype slot of LIST. even though it would be typep 'list, but it's still wrong...

but then, why the integer 42 (i know, why, but still...)?

this can lead to hard to track down bugs...

i propose to signal an error, or return at least 'builtin-classes-have-no-sane-prototypes, or something that gives a hint for users staring at the debugger...

Releated discussion over here:

  http://<email address hidden>/msg00158.html

Searching over the online version of AMOP

  http://www.lisp.org/mop/concepts.html
  http://www.lisp.org/mop/dictionary.html

the only references to CLASS-PROTOTYPE that specify anything are

"Generic Function class-prototype class

Returns a prototype instance of class. Whether the instance is initialized is not specified. The results are undefined if a portable program modifies the binding of any slot of prototype instance.

This generic function signals an error if class has not been finalized."

and a table that says "No behavior is specified for this method beyond that specified for the generic function." in reference to CLASS-PROTOTYPE on standard-class, funcallable-standard-class, forward-referenced-class, and built-in-class.

So...

I don't see anywhere the requirement for the "prototype instance" to be a direct instance. As a matter of fact, I don't see "prototype instance" specified anywhere. It is blatantly underspecified.

I do think that restricting it to direct instances and signalling an error if we cannot provide one is sensible, so that users can rely on

  (bar (class-prototype 'foo))

dispatching on the method specialized on FOO instead of some of its subclasses -- but don't see how this is directly supported by AMOP: it's just the way we decide to interpret the term "prototype instance".

  status confirmed
  importance medium
  tags pcl

Changed in sbcl:
importance: Undecided → Medium
status: New → Confirmed
Attila Lendvai (attila-lendvai) wrote :

another surprise found by Levente:

(typep (sb-pcl::class-prototype (class-of (lambda ()))) 'function) => T

but:

(defgeneric foo (f)
  (:method ((f function))
    (print 42)))

(foo (sb-pcl::class-prototype (class-of (lambda ())))) =>
"The value #<FUNCTION {10014238B1}> is not of type FUNCTION."

this is another argument to signal error in class-prototype for types that can not provide a prototype without surprises.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers