mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-26 13:01:34 +03:00
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:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user