(define impc:ti:if-check
(lambda (ast vars kts request?)
;(println 'if: ast 'request? request?)
(let* ((a (impc:ti:type-check (cadr ast) vars kts #f)) ;request?))
(b (impc:ti:type-check (caddr ast) vars kts request?))
(c (if (null? (cdddr ast))
'()
(impc:ti:type-check (cadddr ast) vars kts request?)))
(t (impc:ti:type-unify (list b c) vars)))
;(t (cl:intersection (if (atom? b) (list b) b) (if (atom? c) (list c) c))))
(if *impc:ti:print-sub-checks* (println 'if:> 'a: a 'b: b 'c: c 't: t))
;; (println 'a: a 'b: b 'c: c 't: t)
(if (null? b)
(set! t c))
(if (null? c)
(set! t b))
;; return intersection of b and c
(if (null? t)
t ;;(log-error 'Compiler 'Error: 'cannot 'unify 'then b 'and 'else c 'in ast) ;(map (lambda (v) (impc:ir:get-type-str v)) b) 'and 'else (map (lambda (v) (impc:ir:get-type-str v)) c) 'clauses 'in ast)
t))))