From 75745901085e2e55b98bd8da2dd25aa5c116f6c2 Mon Sep 17 00:00:00 2001 From: Juan Jose Garcia Ripoll Date: Thu, 4 Dec 2008 16:40:09 +0100 Subject: [PATCH] The optional type checks generated by the compiler were invalid when the type contained a complex function type --- src/CHANGELOG | 5 +++++ src/cmp/cmptype.lsp | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/CHANGELOG b/src/CHANGELOG index d9cbc3bdf..82aa74850 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -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 *** diff --git a/src/cmp/cmptype.lsp b/src/cmp/cmptype.lsp index 5d6512ef4..66e67c426 100644 --- a/src/cmp/cmptype.lsp +++ b/src/cmp/cmptype.lsp @@ -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)))))