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>
This commit is contained in:
2026-03-07 09:33:58 +00:00
parent 5bfb1a9a7e
commit 0e855d5c5e

View File

@@ -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