From 96779768c162c86ce86e23ca6dc736b3e46441fa Mon Sep 17 00:00:00 2001 From: Jared Ramirez Date: Wed, 24 Sep 2025 15:44:25 -0400 Subject: [PATCH] Fix frac unify --- src/canonicalize/Can.zig | 13 +------ src/check/test/type_checking_integration.zig | 2 +- src/check/unify.zig | 36 +++++++++++++------- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/canonicalize/Can.zig b/src/canonicalize/Can.zig index 3013cd424a..b7e0cc3363 100644 --- a/src/canonicalize/Can.zig +++ b/src/canonicalize/Can.zig @@ -6040,17 +6040,6 @@ fn currentScopeIdx(self: *Self) usize { /// This will be used later for builtins like Num.nan, Num.infinity, etc. pub fn addNonFiniteFloat(self: *Self, value: f64, region: base.Region) !Expr.Idx { - // Dec doesn't have infinity, -infinity, or NaN - const requirements = types.Num.Frac.Requirements{ - .fits_in_f32 = true, - .fits_in_dec = false, - }; - - const frac_requirements = types.Num.FracRequirements{ - .fits_in_f32 = requirements.fits_in_f32, - .fits_in_dec = requirements.fits_in_dec, - }; - // then in the final slot the actual expr is inserted const expr_idx = try self.env.addExprAndTypeVar( CIR.Expr{ @@ -6059,7 +6048,7 @@ pub fn addNonFiniteFloat(self: *Self, value: f64, region: base.Region) !Expr.Idx .has_suffix = false, }, }, - Content{ .structure = .{ .num = .{ .frac_unbound = frac_requirements } } }, + .err, region, ); diff --git a/src/check/test/type_checking_integration.zig b/src/check/test/type_checking_integration.zig index cdf7902285..d0c10c354a 100644 --- a/src/check/test/type_checking_integration.zig +++ b/src/check/test/type_checking_integration.zig @@ -743,7 +743,7 @@ test "check type - binops math sub" { \\ \\x = 1 - 0.2 ; - try assertFileTypeCheckPass(source, "Num(Int(Unsigned32))"); + try assertFileTypeCheckPass(source, "Num(Frac(_size))"); } test "check type - binops ord" { diff --git a/src/check/unify.zig b/src/check/unify.zig index f21b9229cf..0c39709e5f 100644 --- a/src/check/unify.zig +++ b/src/check/unify.zig @@ -1185,12 +1185,18 @@ fn Unifier(comptime StoreTypeB: type) type { .int_requirements = b_reqs.int_requirements.unify(a_reqs.int_requirements), .frac_requirements = b_reqs.frac_requirements.unify(a_reqs.frac_requirements), } } } }), - .int_unbound => |a_reqs| self.merge(vars, .{ .structure = .{ .num = .{ - .int_unbound = b_reqs.int_requirements.unify(a_reqs), - } } }), - .frac_unbound => |a_reqs| self.merge(vars, .{ .structure = .{ .num = .{ - .frac_unbound = b_reqs.frac_requirements.unify(a_reqs), - } } }), + .int_unbound => |a_reqs| { + const poly_unbound = self.fresh(vars, .{ .structure = .{ + .num = .{ .int_unbound = b_reqs.int_requirements.unify(a_reqs) }, + } }) catch return Error.AllocatorError; + self.merge(vars, .{ .structure = .{ .num = .{ .num_poly = poly_unbound } } }); + }, + .frac_unbound => |a_reqs| { + const poly_unbound = self.fresh(vars, .{ .structure = .{ + .num = .{ .frac_unbound = b_reqs.frac_requirements.unify(a_reqs) }, + } }) catch return Error.AllocatorError; + self.merge(vars, .{ .structure = .{ .num = .{ .num_poly = poly_unbound } } }); + }, // If the variable inside an int with a precision .int_resolved => |a_int| { @@ -1256,12 +1262,18 @@ fn Unifier(comptime StoreTypeB: type) type { .int_requirements = a_reqs.int_requirements.unify(b_reqs.int_requirements), .frac_requirements = a_reqs.frac_requirements.unify(b_reqs.frac_requirements), } } } }), - .int_unbound => |b_reqs| self.merge(vars, .{ .structure = .{ .num = .{ - .int_unbound = a_reqs.int_requirements.unify(b_reqs), - } } }), - .frac_unbound => |b_reqs| self.merge(vars, .{ .structure = .{ .num = .{ - .frac_unbound = a_reqs.frac_requirements.unify(b_reqs), - } } }), + .int_unbound => |b_reqs| { + const poly_unbound = self.fresh(vars, .{ .structure = .{ + .num = .{ .int_unbound = a_reqs.int_requirements.unify(b_reqs) }, + } }) catch return Error.AllocatorError; + self.merge(vars, .{ .structure = .{ .num = .{ .num_poly = poly_unbound } } }); + }, + .frac_unbound => |b_reqs| { + const poly_unbound = self.fresh(vars, .{ .structure = .{ + .num = .{ .frac_unbound = a_reqs.frac_requirements.unify(b_reqs) }, + } }) catch return Error.AllocatorError; + self.merge(vars, .{ .structure = .{ .num = .{ .num_poly = poly_unbound } } }); + }, // If the variable inside an int with a precision .int_resolved => |b_int| {