promote a lone arithmetic operand

One operand was joined with nothing and came back as it was, so (- c)
over a char was a char where C makes it an int.
This commit is contained in:
2026-10-16 17:04:20 +03:00
parent 52c53c851b
commit f304d92b8d
2 changed files with 14 additions and 4 deletions

View File

@@ -1359,11 +1359,14 @@
;;; (+ (& p) 1) -> (* (struct point))
;;;
;;; `unsigned int' against `int' answers `int', where C says otherwise.
;;; One operand is promoted on its own: (- c), c : char -> int
(define (arithmetic-type expr env)
(fold (lambda (operand joined)
(arith-join joined (expression-type operand env)))
#f
(cdr expr)))
(if (null? (cddr expr))
(promoted-type (expression-type (second expr) env))
(fold (lambda (operand joined)
(arith-join joined (expression-type operand env)))
#f
(cdr expr))))
;;; A pointer, or an array that is one as an operand
(define (address? written)