harec

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

commit e3da1adc553f73caa8dd917bbb27900a6d448286
parent e52b8dd6d4a411f380b8dc046915991623c5b2cf
Author: Sebastian <sebastian@sebsite.pw>
Date:   Thu,  3 Mar 2022 22:29:42 -0500

check: disallow floats for bitwise/modulus exprs

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Msrc/check.c | 22+++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/src/check.c b/src/check.c @@ -808,6 +808,7 @@ check_expr_binarithm(struct context *ctx, enum { BT_INVALID = -1, BT_NUMERIC, + BT_INTEGER, BT_LOGICAL, BT_COMPARISON, BT_EQUALITY, @@ -817,17 +818,20 @@ check_expr_binarithm(struct context *ctx, switch (expr->binarithm.op) { // Numeric arithmetic + case BIN_DIV: + case BIN_MINUS: + case BIN_PLUS: + case BIN_TIMES: + btype = BT_NUMERIC; + break; + // Integer artithmetic case BIN_BAND: case BIN_BOR: - case BIN_DIV: case BIN_LSHIFT: - case BIN_MINUS: case BIN_MODULO: - case BIN_PLUS: case BIN_RSHIFT: - case BIN_TIMES: case BIN_BXOR: - btype = BT_NUMERIC; + btype = BT_INTEGER; break; // Logical arithmetic case BIN_LAND: @@ -918,6 +922,14 @@ check_expr_binarithm(struct context *ctx, } expr->result = p; break; + case BT_INTEGER: + if (!type_is_integer(p)) { + error(ctx, aexpr->loc, expr, + "Cannot perform operation on non-integer %s type", + type_storage_unparse(type_dealias(p)->storage)); + } + expr->result = p; + break; case BT_LOGICAL: if (type_dealias(p)->storage != STORAGE_BOOL) { error(ctx, aexpr->loc, expr,