type a value if as the join of its branches

It had no rule, so _ could not be set from one.
This commit is contained in:
2026-10-19 14:48:43 +03:00
parent 0246f3b54f
commit b458f94566
2 changed files with 22 additions and 0 deletions

View File

@@ -1419,6 +1419,12 @@
;; a shift is the promoted left operand, not a join:
;; (<< l b), l : long -> long; (>> c b), c : char -> int
((<< >>) (promoted-type (expression-type (second expr) env)))
;; a value if is the join of its values, as an operator is of its
;; operands -- and nothing when one of them says nothing
((if) (let ((types (map (cut expression-type <> env)
(if-values (remove comment-form? (cdr expr))))))
(and (every identity types)
(fold (lambda (t joined) (arith-join joined t)) #f types))))
;; a complement is the operand promoted, as a negation is
((~ bit-not bitwise-not) (promoted-type (expression-type (second expr) env)))
;; ...and an increment is the operand unpromoted:
@@ -1479,6 +1485,12 @@
(let ((type (underlying (parse-type written))))
(or (ptr-type? type) (array-type? type)))))
;;; (if t1 v1 t2 v2 e) -> (v1 v2 e)
(define (if-values parts)
(if (and (pair? parts) (pair? (cdr parts)) (pair? (cddr parts)))
(cons (cadr parts) (if-values (cddr parts)))
parts))
(define (arith-join left right)
(cond
((not left) right)