From 92a593b80fe935eb21615dc45b4d7868b254bec6 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 2 Nov 2024 22:34:35 -0400 Subject: Support reductions for comparison operators like == and < --- typecheck.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'typecheck.c') diff --git a/typecheck.c b/typecheck.c index bc3c7982..bff7d080 100644 --- a/typecheck.c +++ b/typecheck.c @@ -1033,6 +1033,12 @@ type_t *get_type(env_t *env, ast_t *ast) auto reduction = Match(ast, Reduction); type_t *iter_t = get_type(env, reduction->iter); + if (reduction->combination && reduction->combination->tag == BinaryOp) { + binop_e op = Match(reduction->combination, BinaryOp)->op; + if (op == BINOP_EQ || op == BINOP_NE || op == BINOP_LT || op == BINOP_LE || op == BINOP_GT || op == BINOP_GE) + return Type(OptionalType, .type=Type(BoolType)); + } + type_t *value_t; type_t *iter_value_t = value_type(iter_t); switch (iter_value_t->tag) { -- cgit v1.2.3