ccl icon indicating copy to clipboard operation
ccl copied to clipboard

defstruct slot initforms not evaluated when doing make-instance of structure-class

Open bon opened this issue 7 years ago • 2 comments

I was getting this exception

$ ccl
Welcome to Clozure Common Lisp Version 1.11  (LinuxX8664)!

CCL is developed and maintained by Clozure Associates. For more information
about CCL visit http://ccl.clozure.com.  To enquire about Clozure's Common Lisp
consulting services e-mail [email protected] or visit http://www.clozure.com.

? (defstruct foo
      (bar (make-array 0 :element-type 'bit) :type simple-bit-vector))
FOO
? (make-instance 'foo)
> Error: The value #1=(MAKE-ARRAY 0 :ELEMENT-TYPE 'BIT), derived from the initform #1#, can not be used to set the value of the slot BAR in #S(FOO :BAR NIL), because it is not of type SIMPLE-BIT-VECTOR.
> While executing: #<CCL::STANDARD-KERNEL-METHOD SHARED-INITIALIZE (STRUCTURE-OBJECT T)>, in process listener(1).
> Type :POP to abort, :R for a list of available restarts.
> Type :? for other options.
1 >

This works

$ ccl
Welcome to Clozure Common Lisp Version 1.11  (LinuxX8664)!

CCL is developed and maintained by Clozure Associates. For more information
about CCL visit http://ccl.clozure.com.  To enquire about Clozure's Common Lisp
consulting services e-mail [email protected] or visit http://www.clozure.com.

? (defstruct foo
      (bar (make-array 0 :element-type 'bit) :type 'simple-bit-vector))
FOO
? (make-instance 'foo)
#S(FOO :BAR (MAKE-ARRAY 0 :ELEMENT-TYPE 'BIT))
?

However the HyperSpec says that the type should not be evaluated.

I haven't checked extensively but the quote appears not to be needed for other types such as fixnum.

bon avatar Nov 10 '17 12:11 bon