commit 0e855d5c5ecc6d5727b2fa4d80ce31008a69bf2f (tree)
parent 5bfb1a9a7e811324eccee2f935923b1d97da86c6
Author: Motiejus <motiejus@jakstys.lt>
Date: Sat, 7 Mar 2026 09:33:58 +0000
sema: add comptime_int → bool coercion in semaCoerce
When coercing comptime_int to bool, produce the correct bool constant
(IP_INDEX_BOOL_TRUE/FALSE) instead of trying to create an IP_KEY_INT
entry with bool type (which wouldn't match the pre-interned bool constants).
Ported from Sema.zig coerce comptime_int → bool path.
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Diffstat:
1 file changed, 10 insertions(+), 0 deletions(-)
diff --git a/stage0/sema.c b/stage0/sema.c
@@ -726,6 +726,16 @@ static AirInstRef semaCoerce(
if (src_ty == TYPE_NONE || target_ty == TYPE_NONE)
return ref;
if (src_ty == IP_INDEX_COMPTIME_INT_TYPE) {
+ // comptime_int → bool: 0 → false, 1 → true.
+ // Ported from Sema.zig coerce comptime_int → bool path.
+ if (target_ty == IP_INDEX_BOOL_TYPE && AIR_REF_IS_IP(ref)) {
+ InternPoolKey src_key = ipIndexToKey(sema->ip, AIR_REF_TO_IP(ref));
+ if (src_key.tag == IP_KEY_INT) {
+ return AIR_REF_FROM_IP(src_key.data.int_val.value_lo != 0
+ ? IP_INDEX_BOOL_TRUE
+ : IP_INDEX_BOOL_FALSE);
+ }
+ }
// comptime_int → float type: convert int to float value.
// Ported from Sema.zig coerce comptime_int → float path.
if ((floatBits(target_ty) > 0