Sema: Support peer type resolution for floats and small integers

This builds on the changes in PR #30053 / commit 484cc15366.

Previously, peer type resolution would always result in a conflict for
fixed-width integer and float types. Now that small integer types can
coerce to floats, peer type resolution can take that into account. This
primarily benefits arithmetic with mixed float and integer operands. If
the integer operand can coerce to the float operand's type, it will do
so without requiring an explicit cast. If the integer type can't coerce,
there will be a compiler error; no float widening will occur. Explicit
casting will still be required to make it work.
This commit is contained in:
Jay Petacat
2026-01-22 00:16:14 -07:00
parent 89c98e2001
commit fcf64761d0
4 changed files with 151 additions and 9 deletions
+11
View File
@@ -10,6 +10,17 @@ test "peer resolve int widening" {
try expectEqual(i16, @TypeOf(c));
}
test "peer resolve small int and float" {
// This only works for integer types that can coerce to the float type.
// Larger integer types will cause a compiler error; no float widening occurs.
var i: u8 = 12;
var f: f32 = 34;
_ = .{ &i, &f };
const x = i + f;
try expectEqual(x, 46.0);
try expectEqual(@TypeOf(x), f32);
}
test "peer resolve arrays of different size to const slice" {
try expectEqualStrings("true", boolToStr(true));
try expectEqualStrings("false", boolToStr(false));