From c0468446f6bafd13b168c8eb6918dd1ce704b5e6 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 24 Feb 2026 18:52:42 +0000 Subject: [PATCH] Ignore const nil "optimization" and fix `c: Maybe(string); c == ""` bug. --- src/check_expr.cpp | 2 ++ src/llvm_backend_expr.cpp | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 14967482f..1cf133f38 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -7421,6 +7421,8 @@ gb_internal CallArgumentData check_call_arguments_proc_group(CheckerContext *c, spaces[max_spaces] = 0; { + // TODO(bill): This is absolutely awful code, that needs improving a lot + bool try_addr = false; isize try_addr_idx = -1; diff --git a/src/llvm_backend_expr.cpp b/src/llvm_backend_expr.cpp index d4acfa196..81d7a4e36 100644 --- a/src/llvm_backend_expr.cpp +++ b/src/llvm_backend_expr.cpp @@ -2971,6 +2971,7 @@ gb_internal lbValue lb_emit_comp(lbProcedure *p, TokenKind op_kind, lbValue left return nil_check; } + if (are_types_identical(a, b)) { // NOTE(bill): No need for a conversion } else if ((lb_is_const(left) && !is_type_array(left.type)) || lb_is_const_nil(left)) { @@ -2983,15 +2984,20 @@ gb_internal lbValue lb_emit_comp(lbProcedure *p, TokenKind op_kind, lbValue left if (internal_check_is_assignable_to(right.type, left.type)) { right = lb_emit_conv(p, right, left.type); } - return lb_emit_comp_against_nil(p, op_kind, right); + if (LLVMTypeOf(left.value) == LLVMTypeOf(right.value)) { + return lb_emit_comp_against_nil(p, op_kind, right); + } } left = lb_emit_conv(p, left, right.type); } else if ((lb_is_const(right) && !is_type_array(right.type)) || lb_is_const_nil(right)) { + if (lb_is_const_nil(right)) { if (internal_check_is_assignable_to(left.type, right.type)) { left = lb_emit_conv(p, left, right.type); } - return lb_emit_comp_against_nil(p, op_kind, left); + if (LLVMTypeOf(left.value) == LLVMTypeOf(right.value)) { + return lb_emit_comp_against_nil(p, op_kind, left); + } } right = lb_emit_conv(p, right, left.type); } else {