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 f30c0733e3
commit 9bbf2dcdaf
2 changed files with 14 additions and 4 deletions

View File

@@ -632,6 +632,13 @@
"ptrdiff_t d = p - xs"))
(test-assert "a number from a pointer is still a pointer"
(emits? (in-fn "(var p (* int) 0) (var r _ (- p 1))") "int * r = p - 1"))
;; one operand was a join with nothing, which left it unpromoted
(test-assert "a negation promotes its operand"
(emits? (in-fn "(var c char 1) (var n _ (- c))") "int n = -c"))
(test-assert "so does a unary plus"
(emits? (in-fn "(var h short 1) (var n _ (+ h))") "int n = +h"))
(test-assert "and leaves a wide one as it is"
(emits? (in-fn "(var l long 1) (var n _ (- l))") "long n = -l"))
;; a compound literal carries its own type, where a brace
;; initializer has none and takes one from its context
(test-assert "a compound literal answers a bare wildcard"