diff --git a/flag-test.lisp b/flag-test.lisp index fc3c925..51e28d3 100644 --- a/flag-test.lisp +++ b/flag-test.lisp @@ -23,7 +23,12 @@ ;;; All the tests except one expect that NAME gets defined via DEFPARAMETER, ;;; whereas by default the flag can't be LET-bound. (defmacro test-define (name val doc &rest rest) - `(flag:define ,name ,val ,doc :def defparameter ,@rest)) + (if (getf rest :type) + `(flag:define ,name ,val ,doc :def defparameter ,@rest) + (let ((assumed-type (cond ((stringp val) 'string) + ((integerp val) 'integer) + (t (type-of val))))) + `(flag:define ,name ,val ,doc :def defparameter :type ,assumed-type ,@rest)))) (test-define *boolean* t "Test boolean flag.") diff --git a/flag.lisp b/flag.lisp index 4c29248..b3c9083 100644 --- a/flag.lisp +++ b/flag.lisp @@ -128,6 +128,8 @@ (fail "The name ~S of the flag is not a string or symbol." flag)) (unless (typep doc 'string) (fail "The flag ~S requires a help string." doc)) + (unless type + (fail "Flag definition ~S lacks a :TYPE" flag)) (unless (typep type '(or symbol cons)) (fail "The type of flag ~S needs to be a proper type specifier. Provided: ~S." flag type)) (dolist (name names) @@ -169,14 +171,6 @@ (value (macro:gensym* :value)) (specified-type type)) - (unless type - ;; Derive type from the type of the default argument. - (let ((declaimed (type:declaimed flag))) - (setf type (cond ((not (member declaimed '(t nil))) - declaimed) - ((constantp default) - (type:upgraded-type-of (eval default))) ; NOLINT - (t nil))))) `(progn (let ((nullable (typep nil ',type))) (register ',flag ',provided-names nullable *flags*) @@ -355,7 +349,7 @@ Parameters: (let* ((flag (first flag+names)) (names (sort (rest flag+names) #'string<)) (doc (documentation flag 'variable)) - (type (or (get flag 'specified-type) (type:declaimed flag))) + (type (or (get flag 'specified-type) (error "can't call type:declaimed on ~S" flag))) (value (and (boundp flag) (symbol-value flag))) (long-form (or long-form (cdr names))) (flag-package (symbol-package flag))) @@ -448,7 +442,7 @@ Parameters: (declare (self (symbol (or null string) &key boolean boolean) (or cons symbol) t boolean boolean)) (let* ((specified-type (get variable 'specified-type)) - (type (or specified-type (type:declaimed variable))) + (type (or specified-type (error "can't call type:declaimed on ~S" variable))) (parser (get variable 'parser))) (cond ((and no-p (typep nil type))