harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 4e8eb0bad77315611e11b3183d03a48c294c67be
parent de848e1c0ee2a2c8f1ee28349e41c119204db430
Author: Armin Weigl <tb46305@gmail.com>
Date:   Fri, 26 Mar 2021 20:10:19 +0100

check_expr_binarithm: use promoted values

Fixes: hare#320

Diffstat:
Msrc/check.c | 7++++---
Atests/25-promotion.ha | 8++++++++
Mtests/configure | 3++-
3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/check.c b/src/check.c @@ -750,9 +750,6 @@ check_expr_binarithm(struct context *ctx, hint, errors); } - expr->binarithm.lvalue = lvalue; - expr->binarithm.rvalue = rvalue; - const struct type *p = type_promote(ctx->store, lvalue->result, rvalue->result); if (p == NULL) { @@ -761,6 +758,10 @@ check_expr_binarithm(struct context *ctx, } lvalue = lower_implicit_cast(p, lvalue); rvalue = lower_implicit_cast(p, rvalue); + + expr->binarithm.lvalue = lvalue; + expr->binarithm.rvalue = rvalue; + if (numeric) { expr->result = p; } else { diff --git a/tests/25-promotion.ha b/tests/25-promotion.ha @@ -0,0 +1,8 @@ +export fn main() void = { + assert(0xFFu8 << 8u16 == 0xFF00u16); + assert(0xFFu8 << 8u8 == 0u8); + assert(0xFFu8 << 24u32 == 0xFF000000u32); + assert(0xFFu8 << 32u32 == 0u32); + assert(0xFFu8 << 32u64 == 0xFF00000000u64); +// assert(0xFFu8 << 64u64 == 0u64); TODO +}; diff --git a/tests/configure b/tests/configure @@ -27,7 +27,8 @@ tests() { 21-tuples \ 22-delete \ 23-errors \ - 24-imports + 24-imports \ + 25-promotion do cat <<EOF tests/$t: libhart.a tests/$t.ha