The optional type checks generated by the compiler were invalid when the type contained a complex function type

This commit is contained in:
Juan Jose Garcia Ripoll 2008-12-04 16:40:09 +01:00
parent ad05b12dd6
commit 7574590108
2 changed files with 19 additions and 2 deletions

View file

@ -189,6 +189,11 @@ ECL 8.9.0:
- DIRECTORY would fail to handle symbolic links under certain conditions.
- The optional type checks generated by the compiler are based on TYPEP and
thus they fail when the declaration type contains a function type (FUNCTION
(...) ...) This is now solved by replacing parts of these types with the
simple type FUNCTION.
;;; Local Variables: ***
;;; mode:text ***
;;; fill-column:79 ***

View file

@ -439,11 +439,23 @@
;; TYPE CHECKING
;;
(defun remove-function-types (type)
(if (atom type)
type
(case (first type)
((OR AND NOT)
(cons (first type) (loop for i in (rest type) collect (remove-function-types i))))
(FUNCTION 'FUNCTION)
(otherwise type))))
(defmacro optional-check-type (&whole whole var-name type &environment env)
"Generates a type check that is only activated for the appropriate
safety settings and when the type is not trivial."
(unless (policy-automatic-check-type-p env)
(cmpnote "Unable to emit check for variable ~A" whole))
(when (policy-automatic-check-type-p env)
(unless (subtypep 't type)
`(check-type ,var-name ,type))))
(setf type (remove-function-types type))
(multiple-value-bind (ok valid)
(subtypep 't type)
(unless (or ok (not valid))
`(check-type ,var-name ,type)))))