zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 247b9a03e44072e1c51ff5cad5e30146296f88bf (tree)
parent 3fadb3583ea8037e97b70593b3863670505c86e9
Author: Motiejus <motiejus@jakstys.lt>
Date:   Sat,  7 Mar 2026 09:13:42 +0000

sema: fix resolvePeerTypes for concrete float types

When both operands are concrete float types (e.g. f32 + f64),
resolvePeerTypes returned the lhs type regardless of width.
Ported from Sema.zig peer_resolve_float strategy: return the
wider float type.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

Diffstat:
Mstage0/sema.c | 11+++++++++++
1 file changed, 11 insertions(+), 0 deletions(-)

diff --git a/stage0/sema.c b/stage0/sema.c @@ -683,6 +683,17 @@ static TypeIndex resolvePeerTypes(Sema* sema, AirInstRef lhs, AirInstRef rhs) { return lhs_ty; return rhs_ty; } + // When both types are concrete float types, pick the wider type. + // Ported from Sema.zig peer_resolve_float strategy. + { + uint16_t lhs_fbits = floatBits(lhs_ty); + uint16_t rhs_fbits = floatBits(rhs_ty); + if (lhs_fbits > 0 && rhs_fbits > 0) { + if (lhs_fbits >= rhs_fbits) + return lhs_ty; + return rhs_ty; + } + } // enum_literal + enum → enum. // Ported from src/Sema.zig peer type resolution for enum_literal. if (lhs_ty == IP_INDEX_ENUM_LITERAL_TYPE