Skip to content

CLOS problem #617

Description

@vlad-km

Case I

CL-USER> (defclass stub () ((name :inivalue nil :initarg :stub-name)))
#<STANDARD-CLASS STUB>
CL-USER> (make-instance 'stub :stub-name "Nox")
#<INSTANCE STUB #(..) >
CL-USER> (describe *)
A CLOS object
             Printed representation: #<INSTANCE STUB #(..) >
             Class: #<STANDARD-CLASS STUB>
             Structure 
             NAME <- ["Nox"]
CL-USER>

The expression (name :inivalue nil :initarg :stub-name) contains an error: :inivalue is used instead of :initvalue. Previously, this error was caught during the defclass compilation stage as an incorrect keyword. PR #497 did not affect the CLOS functionality regarding the handling of invalid &allow-other-keys (which involves a fairly large piece of code).

As a result

CL-USER> (make-instance 'stub)
#<INSTANCE STUB (..) >
CL-USER> (describe *)
A CLOS object
             Printed representation: #<INSTANCE STUB (..) >
             Class: #<STANDARD-CLASS STUB>
             Structure 
             NAME <- ["slot unbound"]
CL-USER> (describe (find-class 'stub))
A CLOS object
             Printed representation: #<STANDARD-CLASS STUB>
             Class: #<STANDARD-CLASS STANDARD-CLASS>
             Structure 
             JSCL::NAME <- [STUB]
             JSCL::DIRECT-SUPERCLASSES <- [(#<STANDARD-CLASS STANDARD-OBJECT>)]
             JSCL::DIRECT-SLOTS <- [((:NAME NAME :INITARGS (:STUB-NAME) :INIVALUE NIL :INITFORM NIL :INITFUNCTION NIL :READERS NIL :WRITERS NIL :ALLOCATION :INSTANCE))]
             JSCL:CLASS-PRECEDENCE-LIST <- [(#<STANDARD-CLASS STUB> #<STANDARD-CLASS STANDARD-OBJECT> #<STANDARD-CLASS T>)]
             JSCL::EFFECTIVE-SLOTS <- [((:NAME NAME :INITFORM NIL :INITFUNCTION NIL :INITARGS (:STUB-NAME) :ALLOCATION :INSTANCE))]
             JSCL::DIRECT-SUBCLASSES <- [NIL]
             JSCL::DIRECT-METHODS <- [NIL]
```lisp

As a result:

```lisp
CL-USER> (defclass kik (stub) ((height :initvalue (random 100) :initarg :kik-height)))
#<STANDARD-CLASS KIK>
CL-USER> (describe (find-class 'kik))
A CLOS object
             Printed representation: #<STANDARD-CLASS KIK>
             Class: #<STANDARD-CLASS STANDARD-CLASS>
             Structure 
             JSCL::NAME <- [KIK]
             JSCL::DIRECT-SUPERCLASSES <- [(#<STANDARD-CLASS STUB>)]
             JSCL::DIRECT-SLOTS <- [((:NAME HEIGHT :INITARGS (:KIK-HEIGHT) :INITVALUE (RANDOM 100) :INITFORM NIL :INITFUNCTION NIL :READERS NIL :WRITERS NIL :ALLOCATION :INSTANCE))]
             JSCL:CLASS-PRECEDENCE-LIST <- [(#<STANDARD-CLASS KIK> #<STANDARD-CLASS STUB> #<STANDARD-CLASS STANDARD-OBJECT> #<STANDARD-CLASS T>)]
             JSCL::EFFECTIVE-SLOTS <- [((:NAME HEIGHT :INITFORM NIL :INITFUNCTION NIL :INITARGS (:KIK-HEIGHT) :ALLOCATION :INSTANCE) (:NAME NAME :INITFORM NIL :INITFUNCTION NIL :INITARGS (:STUB-NAME) :ALLOCATION :INSTANCE))]
             JSCL::DIRECT-SUBCLASSES <- [NIL]
             JSCL::DIRECT-METHODS <- [NIL]

CL-USER> (progn (setq pp (make-instance 'kik :stub-name "Box" )) t)
T
CL-USER> (describe pp)
A CLOS object
             Printed representation: #<INSTANCE KIK (..) #(..) >
             Class: #<STANDARD-CLASS KIK>
             Structure 
             HEIGHT <- ["slot unbound"]
             NAME <- ["Box"]
CL-USER> (slot-value pp 'height)
SIMPLE-ERROR: The slot HEIGHT is unbound in the object #<INSTANCE KIK (..) #(..) >.
CL-USER> (let () (setf (slot-value pp 'height) 109))
109

Why does the form (progn (setq pp (make-instance 'kik :stub-name "Box" )) t) or (let () (setf (slot-value pp 'height) 109)) ?
There seems to be an issue with SETF in top-level evaluation. @davazp, hey ;)

Case II

CL-USER> (make-instance 'kik :kik-height 123)
TYPE-ERROR: 123 is not a (OR STRING SYMBOL CHARACTER).
    at https://jscl-project.github.io/jscl.js:43039:7
    at https://jscl-project.github.io/jscl.js:43042:3
    at JSCL_USER_ERROR (https://jscl-project.github.io/jscl.js:43043:3)
    at internals.mvcall (https://jscl-project.github.io/jscl.js:73:10)
    at https://jscl-project.github.io/jscl.js:10147:78
    at internals.Symbol.JSCL_USER_STRING [as fvalue] (https://jscl-project.github.io/jscl.js:10148:3)
    at https://jscl-project.github.io/jscl.js:39171:97
    at https://jscl-project.github.io/jscl.js:39174:3
    at https://jscl-project.github.io/jscl.js:39188:3
    at https://jscl-project.github.io/jscl.js:39190:3
    at https://jscl-project.github.io/jscl.js:39191:3
    at https://jscl-project.github.io/jscl.js:39199:3
    at internals.Symbol.JSCL_USER_MOPOBJECTSLOTS [as fvalue] (https://jscl-project.github.io/jscl.js:39200:3)

We are interested in at internals.Symbol.JSCL_USER_MOPOBJECTSLOTS.

      ((or (numberp place)
                 (symbolp place))
             (push (concat (string place) " ") result))

Here, (string place) is what causes the TYPE-ERROR:.

The string function was fixed earlier, but not all of its occurrences were tracked down.

Something like that.

Regrettably, I am still unable to apply the fixes and open a PR myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions