From 2b0fb52f6576b3a78b9150c09fe6403baa6039f3 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Wed, 25 Jun 2025 00:55:29 +0200 Subject: [PATCH] Fix regression: Enum inference with compare operators #2241 --- src/compiler/llvm_codegen_expr.c | 1 + src/compiler/sema_expr.c | 3 ++- .../test_suite/enumerations/enum_compare_inference.c3 | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test/test_suite/enumerations/enum_compare_inference.c3 diff --git a/src/compiler/llvm_codegen_expr.c b/src/compiler/llvm_codegen_expr.c index 1b13b87d7..38b98a165 100644 --- a/src/compiler/llvm_codegen_expr.c +++ b/src/compiler/llvm_codegen_expr.c @@ -3328,6 +3328,7 @@ static inline LLVMValueRef llvm_emit_mult_int(GenContext *c, Type *type, LLVMVal static void llvm_emit_slice_comp(GenContext *c, BEValue *be_value, BEValue *lhs, BEValue *rhs, BinaryOp binary_op) { + bool want_match = binary_op == BINARYOP_EQ; Type *array_base_type = type_lowering(lhs->type->array.base); diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index b0c1e79e3..4f29436a1 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -1227,7 +1227,8 @@ static inline bool sema_binary_analyse_with_inference(SemaContext *context, Expr { const static int op_table[BINARYOP_LAST + 1] = { [BINARYOP_AND] = 1, [BINARYOP_OR] = 1, [BINARYOP_CT_AND] = 1, [BINARYOP_CT_OR] = 1, - [BINARYOP_EQ] = 2, [BINARYOP_NE] = 2 }; + [BINARYOP_EQ] = 2, [BINARYOP_NE] = 2, [BINARYOP_GT] = 2, [BINARYOP_GE] = 2, + [BINARYOP_LE] = 2, [BINARYOP_LT] = 2 }; int op_result = op_table[op]; if (op_result == 1) return true; // If lhs or rhs is an initializer list, infer diff --git a/test/test_suite/enumerations/enum_compare_inference.c3 b/test/test_suite/enumerations/enum_compare_inference.c3 new file mode 100644 index 000000000..14b9f61cf --- /dev/null +++ b/test/test_suite/enumerations/enum_compare_inference.c3 @@ -0,0 +1,11 @@ +import std; +enum Foo +{ + A, B, C +} + +fn int main() +{ + assert(Foo.A < B); + return 0; +} \ No newline at end of file