alex-gutev / cl-form-types

Library for determining the types of Common Lisp forms based on information stored in the environment.
MIT License
19 stars 1 forks source link

`values` type needs more normalization (values inside values) #8

Open digikar99 opened 2 years ago

digikar99 commented 2 years ago

Example:

(declaim (ftype (function (*) (values &rest number)) bar))
(defun bar (l) (values-list l))
(cl-form-types:form-type '(values "" (bar x)) nil)
; => (VALUES (SIMPLE-ARRAY CHARACTER (0)) (VALUES &REST NUMBER))
; should rather just be (VALUES (SIMPLE-ARRAY CHARACTER (0)) (OR NULL NUMBER)) 
; SBCL does the addition of (OR NULL ...) for (defun baz (l) (values "" (bar l)))
alex-gutev commented 2 years ago

That definitely should not happen. It will fix it

alex-gutev commented 2 years ago

Should be fixed in f46969b.

digikar99 commented 2 years ago

At least one corner case seems to remain: what if l given to bar is an empty-list? In this case (bar nil) returns no value. If I understand correctly, the (or null number) deduced by SBCL for baz as defined above is therefore (more?) correct.

(cl-form-types:form-type '(values "" (bar nil)) nil) ;=> (VALUES (SIMPLE-ARRAY CHARACTER (0)) NUMBER)
; But should be: (VALUES (SIMPLE-ARRAY CHARACTER (0)) (OR NULL NUMBER))
;=>

In fact, you could also add an &optional at the end? But this is... erm... optional. There might be other cases in which &optional might be an issue; so &optional is not urgent I think.