Changeset 14305


Ignore:
Timestamp:
Sep 28, 2010, 5:41:16 PM (9 years ago)
Author:
rme
Message:

Use require-type in defstruct accessors to check type of slot values
when checking declarations (e.g., with safety 3).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/lib/defstruct.lisp

    r14258 r14305  
    207207                     (t `(uvref ,arg ,offset)))))
    208208    `((defun ,name (,arg)
    209         ,(if (eq type 't) form `(the ,type ,form)))
     209        ,(cond ((eq type t) form)
     210               ((nx-declarations-typecheck env)
     211                ;; TYPE may be unknown.  For example, it may be
     212                ;; forward-referenced.  Insert a run-time check in
     213                ;; this case.
     214                `(require-type ,form ',type))
     215               (t `(the ,type ,form))))
    210216      ,@(unless (ssd-r/o slot)
    211217          `((defun (setf ,name) (,value ,arg)
    212               ,(if (eq type 't)
    213                  `(setf ,form ,value)
    214                  `(the ,type (setf ,form (typecheck ,value ,type))))))))))
     218              ,(cond
     219                ((eq type t) `(setf ,form ,value))
     220                ((nx-declarations-typecheck env)
     221                 ;; Checking the type of SETF's return value seems
     222                 ;; kind of pointless here.
     223                 `(require-type (setf ,form (typecheck ,value ,type)) ',type))
     224                (t
     225                 `(the ,type (setf ,form (typecheck ,value ,type)))))))))))
    215226
    216227(defun defstruct-reftype (type)
Note: See TracChangeset for help on using the changeset viewer.